I am new to Serilog and I am struggling with displaying the class name only when required without having to add {SourceContext:l}
to each log message. I am aware I can just write the code as:
Log.ForContext<Class1>().Verbose("message {SourceContext:l}");
I have the logger being setup as below:
var log = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo
.ColoredConsole(outputTemplate: "{Timestamp:G} [{Level}] {SourceContext} {Message}{NewLine:l}{Exception:l}")
.CreateLogger();
I am hoping to only have the class name displayed when the class has been specified as seen here.
Log.ForContext<Class1>().Verbose("message");
And not displayed if the log is created like.
Log.Verbose("message");
However on the above example it will print a log out in the format of '{SourceContext} message' instead of just 'message' which is not what I want.