Reputation: 4759
I am facing a trouble with using trace in Azure APIM policies.
For example below trace message
<set-variable name="expiresOn" value="@(Uri.EscapeDataString(DateTime.UtcNow.AddDays(30).ToString("yyyy-MM-ddTHH:mm:ssZ")))" />
<trace source="policy" severity="information">Generated expiresOn value: @(context.Variables["expiresOn"])</trace>
<!-- Assign full URL to a variable and log it -->
<set-variable name="tokenRequestUrl" value="@($"https://myapp.com/rest/jwt/?expiresOn={context.Variables["expiresOn"]}")" />
<trace source="policy" severity="information">Token request URL: @(context.Variables.GetValueOrDefault("tokenRequestUrl", "NULL"))</trace>
these are all only showing this in app insight
Why they are not printing the values?? or the values are not really assigning??
what I did wrong here
Upvotes: 0
Views: 23
Reputation: 7810
APIM policy expressions (https://learn.microsoft.com/en-us/azure/api-management/api-management-policy-expressions) can't be used in the middle of attribute or element value. The whole value should be either an expression (begins with @( or ${) or it is treated as a static text.
In your case try:
<trace source="policy" severity="information">@("Generated expiresOn value: " + (string)context.Variables["expiresOn"])</trace>
Upvotes: 0
Reputation: 6778
Try using the multi-statement syntax inside trace
, for example:
@{return context.Variables.GetValueOrDefault<string>("tokenRequestUrl", "NULL");}
P.S. You seem to be missing the <message>
node inside trace
.
Upvotes: 1