1

I'm using serilog/serilog-sinks-xamarin as described here

In .Android project I added following code:

    Log.Logger = new LoggerConfiguration().WriteTo.AndroidLog().Enrich.WithProperty("Tag", "CustomTag").CreateLogger();

And calling it from portable class:

Log.Information("App is Starting");

I can see this line in device log, however tag is blank: missing tag

SushiHangover
  • 73,120
  • 10
  • 106
  • 165

1 Answers1

0

The Enrich.WithProperty has to be set to Constants.SourceContextPropertyName which in Serilog is the constant string of the value: SourceContext.

Use "SourceContext" in your LoggerConfiguration:

Log.Logger = new LoggerConfiguration().WriteTo.AndroidLog().Enrich.WithProperty("SourceContext", "CustomTag").CreateLogger();

In serilog-sinks-xamarin, the log TAG is assigned via:

var tag = logEvent.Properties.Where(x => x.Key == Constants.SourceContextPropertyName).Select(x => x.Value.ToString("l", null)).FirstOrDefault() ?? "";

re: https://github.com/serilog/serilog-sinks-xamarin/blob/dec633b488a5c7dd3f3c9a017b972eaf101a177c/src/Serilog.Sinks.Xamarin.Droid/Sinks/Xamarin/AndroidLogSink.cs#L54

re: https://github.com/serilog/serilog/blob/32e0c9578db720add74720bceb62bd46967694c4/src/Serilog/Core/Constants.cs#L27

SushiHangover
  • 73,120
  • 10
  • 106
  • 165