Do you use the best trace logging library?
Last updated by Brook Jeynes [SSW] over 1 year ago.See historyDid you know that writing your own logging infrastructure code wastes time? There are awesome logging abstractions in .NET Core and .NET 5+ that you should use instead!
These abstractions allow you to:
- Create log entries in a predictable and familiar fashion - you use the same patterns for logging in a Background Service as you would in a Blazor WASM app (just some slightly different bootstrapping 😉)
- Use Dependency Injection; your code doesn't take a dependency on a particular framework (as they are abstractions)
- Filter output based off severity (Verbose/Debug/Info/Warning/Error) - so you can dial it up or down without changing code
- Have different logs for different components of your application (e.g. a Customer Log and an Order Log)
- Multiple logging sinks - where the logs are written to e.g. log file, database, table storage, or Application Insights
- Supports log message templates allowing logging providers to implement semantic or structured logging
- Can be used with a range of 3rd party logging providers
Read more at Logging in .NET Core and ASP.NET Core
_logger.LogInformation("Getting item {Id} at {RequestTime}", id, DateTime.Now);
Good example - Using templates allows persisting structured log data (DateTime is a complex object)