|
| 1 | +using Serilog; |
| 2 | +using System.Diagnostics; |
| 3 | + |
| 4 | +var builder = WebApplication.CreateBuilder(args); |
| 5 | + |
| 6 | +// Add services to the container. |
| 7 | +builder.Services.AddControllersWithViews(); |
| 8 | + |
| 9 | +builder.Host.UseSerilog((ctx, lc) => lc.ReadFrom.Configuration(ctx.Configuration)); |
| 10 | + |
| 11 | +//var _logger = new LoggerConfiguration() |
| 12 | +// .Enrich.FromGlobalLogContext() |
| 13 | +// .WriteTo.File("./logs/log-.txt", rollingInterval: RollingInterval.Day) |
| 14 | +// .WriteTo.Seq("http://localhost:5341", Serilog.Events.LogEventLevel.Warning) |
| 15 | +// .Enrich.WithProperty("ServiceName", "SomeConsumer") |
| 16 | +// .MinimumLevel.Debug() |
| 17 | +// .CreateLogger(); |
| 18 | + |
| 19 | +//var _logger = new LoggerConfiguration() |
| 20 | +// .Enrich.FromLogContext() |
| 21 | +// .Enrich.WithProcessId() |
| 22 | +// .Enrich.WithProcessName() |
| 23 | +// .Enrich.WithProperty("CustomerKey", "ABC123") |
| 24 | +// .WriteTo.File("./logs/log-.txt", rollingInterval: RollingInterval.Day) |
| 25 | +// .CreateLogger(); |
| 26 | + |
| 27 | + |
| 28 | +//var _logger = new LoggerConfiguration() |
| 29 | +// .Enrich.FromLogContext() |
| 30 | +// .Enrich.WithProcessId() |
| 31 | +// .Enrich.WithProcessName() |
| 32 | +// .Enrich.WithProperty("CustomerKey", "ABC123") |
| 33 | +// .Enrich.WithProperty("PID", Process.GetCurrentProcess().Id) // 9840 |
| 34 | +// .WriteTo.File("./logs/log-.txt", rollingInterval: RollingInterval.Day, |
| 35 | +// outputTemplate: "{Timestamp:HH:mm:ss} {Message} {CustomerKey} {PID}{NewLine}{Exception}" |
| 36 | +// ) |
| 37 | +// .CreateLogger(); |
| 38 | + |
| 39 | + |
| 40 | +//builder.Logging.AddSerilog(_logger); |
| 41 | +var app = builder.Build(); |
| 42 | + |
| 43 | +// Configure the HTTP request pipeline. |
| 44 | +if (!app.Environment.IsDevelopment()) |
| 45 | +{ |
| 46 | + app.UseExceptionHandler("/Home/Error"); |
| 47 | + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. |
| 48 | + app.UseHsts(); |
| 49 | +} |
| 50 | + |
| 51 | +app.UseHttpsRedirection(); |
| 52 | +app.UseStaticFiles(); |
| 53 | + |
| 54 | +app.UseSerilogRequestLogging(); |
| 55 | + |
| 56 | +app.UseRouting(); |
| 57 | + |
| 58 | +app.UseAuthorization(); |
| 59 | + |
| 60 | +app.MapControllerRoute( |
| 61 | + name: "default", |
| 62 | + pattern: "{controller=Home}/{action=Index}/{id?}"); |
| 63 | + |
| 64 | +app.Run(); |
0 commit comments