0

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.

  • 1
    Does this answer your question? [C# ASP.NET Core Serilog add class name and method to log](https://stackoverflow.com/questions/47576733/c-sharp-asp-net-core-serilog-add-class-name-and-method-to-log) – Yong Shun Jan 18 '22 at 08:07

0 Answers0