|
1 | | -usingAspectCore.Extensions.Hosting; |
2 | | -usingDestiny.Core.Flow.SeriLog; |
3 | | -usingMicrosoft.AspNetCore.Hosting; |
4 | | -usingMicrosoft.Extensions.Configuration; |
5 | | -usingMicrosoft.Extensions.Hosting; |
6 | | -usingMicrosoft.Extensions.Logging; |
7 | | -usingSerilog; |
8 | | -usingSerilog.Events; |
9 | | -usingSystem; |
10 | | -usingSystem.IO; |
11 | | - |
12 | | -namespaceDestiny.Core.Flow.API |
13 | | -{ |
14 | | -publicclassProgram |
15 | | -{ |
16 | | -publicstaticvoidMain(string[]args) |
17 | | -{ |
18 | | - |
19 | | -//SeriLogLogger.SetSeriLoggerToFile("Logs",string.Empty); |
20 | | -CreateHostBuilder(args).Build().Run(); |
21 | | -} |
22 | | -publicstaticIHostBuilderCreateHostBuilder(string[]args)=> |
23 | | -Host.CreateDefaultBuilder(args) |
24 | | -.ConfigureWebHostDefaults(webBuilder=> |
25 | | -{ |
26 | | -webBuilder.UseStartup<Startup>() |
27 | | -//待封装 |
28 | | -.UseSerilog((webHost,configuration)=>{ |
29 | | - |
30 | | -//得到配置文件 |
31 | | -varserilog=webHost.Configuration.GetSection("Serilog"); |
32 | | -//最小级别 |
33 | | -varminimumLevel=serilog["MinimumLevel:Default"]; |
34 | | -//日志事件级别 |
35 | | -varlogEventLevel=(LogEventLevel)Enum.Parse(typeof(LogEventLevel),minimumLevel); |
36 | | - |
37 | | - |
38 | | -configuration.ReadFrom. |
39 | | -Configuration(webHost.Configuration.GetSection("Serilog")).Enrich.FromLogContext().WriteTo.Console(logEventLevel); |
40 | | -configuration.WriteTo.Map(le=>MapData(le), |
41 | | -(key,log)=> |
42 | | -log.Async(o=>o.File(Path.Combine("Logs",@$"{key.time:yyyy-MM-dd}\{key.level.ToString().ToLower()}.txt"),logEventLevel))); |
43 | | - |
44 | | -(DateTimetime,LogEventLevellevel)MapData(LogEventlogEvent) |
45 | | -{ |
46 | | - |
47 | | -return(newDateTime(logEvent.Timestamp.Year,logEvent.Timestamp.Month,logEvent.Timestamp.Day,logEvent.Timestamp.Hour,logEvent.Timestamp.Minute,logEvent.Timestamp.Second),logEvent.Level); |
48 | | -} |
49 | | - |
50 | | -}).ConfigureLogging((hostingContext,builder)=> |
51 | | -{ |
52 | | -builder.ClearProviders(); |
53 | | -builder.SetMinimumLevel(LogLevel.Information); |
54 | | - |
55 | | -builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); |
56 | | -builder.AddConsole(); |
57 | | -builder.AddDebug(); |
58 | | -}); |
59 | | -}).UseDynamicProxy();//*/;//aspcectcore; |
60 | | - |
61 | | - |
62 | | -} |
63 | | -} |
| 1 | +usingAspectCore.Extensions.Hosting; |
| 2 | +usingDestiny.Core.Flow.SeriLog; |
| 3 | +usingMicrosoft.AspNetCore.Hosting; |
| 4 | +usingMicrosoft.Extensions.Configuration; |
| 5 | +usingMicrosoft.Extensions.Hosting; |
| 6 | +usingMicrosoft.Extensions.Logging; |
| 7 | +usingSerilog; |
| 8 | +usingSerilog.Events; |
| 9 | +usingSystem; |
| 10 | +usingSystem.IO; |
| 11 | + |
| 12 | +namespaceDestiny.Core.Flow.API |
| 13 | +{ |
| 14 | +publicclassProgram |
| 15 | +{ |
| 16 | +publicstaticvoidMain(string[]args) |
| 17 | +{ |
| 18 | + |
| 19 | +//SeriLogLogger.SetSeriLoggerToFile("Logs",string.Empty); |
| 20 | +CreateHostBuilder(args).Build().Run(); |
| 21 | +} |
| 22 | +publicstaticIHostBuilderCreateHostBuilder(string[]args)=> |
| 23 | +Host.CreateDefaultBuilder(args) |
| 24 | +.ConfigureWebHostDefaults(webBuilder=> |
| 25 | +{ |
| 26 | +webBuilder.UseStartup<Startup>() |
| 27 | +//待封装 |
| 28 | +.UseSerilog((webHost,configuration)=>{ |
| 29 | + |
| 30 | +//得到配置文件 |
| 31 | +varserilog=webHost.Configuration.GetSection("Serilog"); |
| 32 | +//最小级别 |
| 33 | +varminimumLevel=serilog["MinimumLevel:Default"]; |
| 34 | +//日志事件级别 |
| 35 | +varlogEventLevel=(LogEventLevel)Enum.Parse(typeof(LogEventLevel),minimumLevel); |
| 36 | + |
| 37 | + |
| 38 | +configuration.ReadFrom. |
| 39 | +Configuration(webHost.Configuration.GetSection("Serilog")).Enrich.FromLogContext().WriteTo.Console(logEventLevel); |
| 40 | +configuration.WriteTo.Map(le=>MapData(le), |
| 41 | +(key,log)=> |
| 42 | +log.Async(o=>o.File(Path.Combine("Logs",@$"{key.time:yyyy-MM-dd}\{key.level.ToString().ToLower()}.txt"),logEventLevel))); |
| 43 | + |
| 44 | +(DateTimetime,LogEventLevellevel)MapData(LogEventlogEvent) |
| 45 | +{ |
| 46 | + |
| 47 | +return(newDateTime(logEvent.Timestamp.Year,logEvent.Timestamp.Month,logEvent.Timestamp.Day,logEvent.Timestamp.Hour,logEvent.Timestamp.Minute,logEvent.Timestamp.Second),logEvent.Level); |
| 48 | +} |
| 49 | + |
| 50 | +}).ConfigureLogging((hostingContext,builder)=> |
| 51 | +{ |
| 52 | +builder.ClearProviders(); |
| 53 | +builder.SetMinimumLevel(LogLevel.Information); |
| 54 | + |
| 55 | +builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); |
| 56 | +builder.AddConsole(); |
| 57 | +builder.AddDebug(); |
| 58 | +}); |
| 59 | +}).UseDynamicProxy();//*/;//aspcectcore; |
| 60 | + |
| 61 | + |
| 62 | +} |
| 63 | +} |