Trying to grasp the point of Serilog in ASP.NET Core on Azure?
I've been working in ASP.NET core for a few months. I really like the default logging. A coworker setup serilog to send the logs to App Insights. I then dove in and tuned the logs because we discovered the Console logger was really slowing things down. I learned a lot along the way.
Serilog is obviously more mature and has more sinks than the built in logging. However, I'm not sure if its worth it. Please help me to see what I'm missing.
I'm dealing with the narrow perspective of Console and application insights sinks.
Pros:
- A responsive developer community. this issue I opened inspired a core contributor to implement a proof of concept.
- Much nicer console appender
- Better formatting options
- Cooler color themes.
- A bunch of sinks I'll probably never use.
- The enrichers are arguably more convenient than using BeginScope() in a filter for global level enrichment that gets disposed on request complete.
- The `LogContext.PushProperty is more convenient for global stuff than BeginScope in a filter that gets disposed on request complete.
Cons:
- The console logger seems to support BeginScope(), but The Application Insights sink does not seem to.
- Begin scope is an awesome "middle ground" between per line logging objects and
LogContext.PushProperty - It seems that with the serilog appsettings.json package I can configure log level at the root level per namespace/category, but I can only reduce that verbosity per sink globally via
restrictedToMinimumLevelE.g.:
"Serilog": { "Using": [ "Serilog.Sinks.Console" ], "MinimumLevel": { "Default": "Debug", "Override": { "MediatR.IMediator": "Information", "Microsoft": "Information", "Microsoft.AspNetCore.Mvc": "Information", "Microsoft.EntityFrameworkCore": "Warning", "Foo": "Information" } }, "WriteTo": [ { "Name": "Console", "Args": { "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console", "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {RequestId}-{SourceContext} {$Scope}: {Message:lj}{NewLine}{Exception}" }, "restrictedToMinimumLevel": "Information" }, { "Name": "ApplicationInsightsTraces", "Args": { "instrumentationKey": "XXXXXXXXXXX" } } ], "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId", "WithExceptionDetails" ], "Properties": { "Application": "Foo" } },
Using the above example the all output is limited to Information and greater on the console. I'd honestly like to just restrict "Microsoft.AspNetCore.Mvc" and keep the other stuff. I could do this just fine with vanilla ASP.NET core logging.
So in summary, I feel like Serilog gives me nicer console formatting, but I lose configurability. Ilogger doesn't seem to have transformations like destructure, which honestly I could achieve similarly via BeginScope() wrappers and extension methods.
0 comments:
Post a Comment