博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

aspnetcore 日志 serilog-aspnetcore

Posted on 2018-10-19 11:36  生命如风  阅读(796)  评论(0编辑  收藏  举报

serilog-aspnetcore

 

https://github.com/serilog/serilog-aspnetcore

 

public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                .MinimumLevel.Override("System", LogEventLevel.Warning)
                .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)
                .Enrich.FromLogContext()
                .WriteTo.File(
                                @"Log/log.txt",
                                fileSizeLimitBytes: 1_000_000,
                                rollOnFileSizeLimit: true,
                                flushToDiskInterval: TimeSpan.FromSeconds(1)

                )
                .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Literate)
                .CreateLogger();

            BuildWebHost(args).Run();
        }