2020-09-21

.NET Core 下使用 Serilog 记录日志

Serilog

Like many other libraries for .NET, Serilog provides diagnostic logging to files, the console, and elsewhere. It is easy to set up, has a clean API, and is portable between recent .NET platforms.
Unlike other logging libraries, Serilog is built with powerful structured event data in mind.

最佳实践

控制台项目

在项目中添加下面几个组件包

Install-Package Serilog.Extensions.LoggingInstall-Package Serilog.Sinks.ConsoleInstall-Package Serilog.Sinks.File
class Program{ static async Task Main(string[] args) {  Log.Logger = new LoggerConfiguration()   .MinimumLevel.Information()   .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)#if DEBUG   .MinimumLevel.Override("Xxx", LogEventLevel.Debug)#else   .MinimumLevel.Override("Xxx", LogEventLevel.Information)

No comments:

Post a Comment