Пример #1
0
        public static IApplicationBuilder UseExceptionMiddleware(this IApplicationBuilder appBuilder)
        {
            var logger = new LoggerConfiguration()
                         .MinimumLevel.Information()
                         .MinimumLevel.Override("System", LogEventLevel.Warning)
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                         .MinimumLevel.Override("RFID", LogEventLevel.Information)
                         //.MinimumLevel.Verbose()
                         //.MinimumLevel.Override("System", LogEventLevel.Verbose)
                         //.MinimumLevel.Override("Microsoft", LogEventLevel.Verbose)
                         //.MinimumLevel.Override("RFID", LogEventLevel.Verbose)
                         .WriteTo.Async(x => x.RollingFile(pathFormat: "Logs\\errors-{Date}.log", fileSizeLimitBytes: 1_000_000, outputTemplate: outputTemplate))
                         .WriteTo.Async(x => x.Console())
                         .Enrich.WithDemystifiedStackTraces()
                         .Enrich.FromLogContext()
                         .CreateLogger();

            Log.Logger = logger;

            return(appBuilder
                   .UseMiddleware <ExceptionMiddleware>()
                   .UseSerilogRequestLogging());
        }