1

Our application uses the Serilog NuGet package to write logs to Loggly, and I am using GlobalLogContextto add a custom property like this:

using (GlobalLogContext.PushProperty("TransactionActivityId", activityId))
{
    _logger.LogInformation("Test log message");
}

We also set up the logger by doing

.UseSerilog((context, loggerConfiguration) => loggerConfiguration
    .ReadFrom.Configuration(context.Configuration)
    .Enrich.FromGlobalLogContext())

In Loggly, I see the property in the "raw message" section, but the custom property is not showing up in the json section. enter image description here

What has to be done in order for Loggly to show this property in the json section?

Ian Yang
  • 25
  • 5
  • do you have the enrich bit wired up per https://github.com/serilog-contrib/serilog-enrichers-globallogcontext ? – Ruben Bartelink Jun 11 '22 at 13:57
  • Yes. I followed those instructions and have `.Enrich.FromGlobalLogContext()`, and that was how I was able to get the property to show up in the "raw message" section. Sorry I shouldn't made that clear. – Ian Yang Jun 11 '22 at 16:19
  • Apologies for not reading! I assume there is some whitelist somewhere that is lifting `SourceContext` into the highlghted/indexed properties; unfortunately I have zero knowledge of Loggly's config so can't say whether that's configured in Loggly or in the Loggly sink. – Ruben Bartelink Jun 12 '22 at 11:24
  • Funny thing is, if I had a structured message like `LogInformation("Test message {ActivityId}", activityId)`, the `activityId` gets picked up by loggly automatically and shows up as a property under json. But I don't want to include the activity Id in every message body. – Ian Yang Jun 12 '22 at 18:04

0 Answers0