I am very new to Serilog and I was trying to find a way to log the line number, member name, and file name in my logs. I see that reflection works but it is poor performance and I found that you could use the attribute class to get the same information without penalty. I don't know how you would implement that into Serilog Logger. I currently have my Logger set as this.
void createAppLogger(IConfiguration configuration)
{
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.Enrich.FromLogContext()
.Enrich.WithEnvironmentName()
.Enrich.FromLogContext()
.WriteTo.Console()
.Enrich.WithProperty("Caller", CallerLineNumberAttribute)
.Enrich.FromLogContext()
.CreateLogger();
}
However when I call the CallerLineNumber, it tells me its not valid in the given context. I tried searching for any clues or answer to this but I couldn't exactly find it.