serilog / serilog-extensions-logging

Serilog provider for Microsoft.Extensions.Logging
Apache License 2.0
313 stars 100 forks source link

WriteOut the logger-Name ILogger<T> #63

Closed stefc closed 7 years ago

stefc commented 7 years ago

How I get the name of the Logger class in SeriLog dump out? The EventId I get with a property. But If I created a Logger

factory.CreateLogger<MySampleService>()

I want to see something like "MySampleService" in my output?

Microsoft default implementation writes

info: MySampleService[4711]
      Framework: .NET Core 4.6.24410.01
fail: MySampleService[4711]
      Error System.ArgumentException: Wrong Argument
System.ArgumentException: Wrong Argument

With the Serilog Provider I get

2016-11-24 11:12:02 { Id: 4711 }   [Information] OS: "Microsoft Windows 6.1.7601 S"
2016-11-24 11:12:02 { Id: 4711 }   [Information] Framework: ".NET Core 4.6.24410.01"
2016-11-24 11:12:02 { Id: 4711 }   [Error] Error "System.ArgumentException: Wrong Argument"
System.ArgumentException: Wrong Argument
.WriteTo.ColoredConsole(
                        LogEventLevel.Verbose, 
                        "{Timestamp:yyyy-MM-dd HH:mm:ss} {EventId} [{Level}] {Message}{NewLine}{Exception}")
skomis-mm commented 7 years ago

@stefc , you need include {SourceContext} to output template.

stefc commented 7 years ago

@skomis-mm Thanks this is what I look for!