I'm pushing custom property using LogContext.PushProperty via serilog like below but when I look at app insights this custom property is being added to only for the custom event logs in this method. i.e "Fetched the response from azure cache for redis with Cache Key:"
public async Task<T> GetFromCacheAsync<T>(string key) where T: class
{
var stopwatch = Stopwatch.StartNew();
var cachedResponse = await _distributedCache.GetStringAsync(key);
if (string.IsNullOrEmpty(cachedResponse)) { return null; }
LogContext.PushProperty(IS_CACHED_RESPONSE, "True");
Log.Information($"Fetched the response from azure cache for redis with Cache Key: {key} in Time: {stopwatch.Elapsed}");
return JsonConvert.DeserializeObject<T>(cachedResponse);
}
App Insight Logs Where Custom property is pushed
App Insight Logs Where Custom property is not found within same operationID/RequestId
The above code is from the infrastructure layer (we follow clean architecture), however, properties pushed from middleware i.e requestidentfier and cxidentifier are always found in custom properties (please refer to screenshot) and when I sink logs to file, the property iscachedResponse is always empty except when hits part of getfromcacheasync code. But requestidentifier and cxidentifier are always available.
"outputTemplate": "{Timestamp:o} [{Level:u3}] ({SourceContext}) [isCachedResponse: {IsCachedResponse}] [cxIdentifier: {CxIdentifier}] [requestIdentifier: {RequestIdentifier}] [marketCode: {MarketCode}] {Message}{NewLine}{Exception}"

