public static void Main(string[] args) { _configuration = new ConfigurationBuilder() .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) .AddJsonFile("appsettings.json") .AddCommandLine(args) .AddEnvironmentVariables() .AddUserSecrets(Assembly.GetExecutingAssembly()) .Build(); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(_configuration) .WriteTo.File(new JsonFormatter(), Path.Combine("logs", "log.json"), shared: true, rollingInterval: RollingInterval.Day, fileSizeLimitBytes: 10_000_000, rollOnFileSizeLimit: true) .WriteTo.ColoredConsole() .CreateLogger(); try { Log.Information("Starting..."); CreateHostBuilder(args).Build().Run(); } catch (Exception ex) { Log.Fatal(ex, "Failed start"); } finally { Log.CloseAndFlush(); } }
public static void Main(string[] args) { var datasulSeqSettings = new DatasulSeqSettings(); Configuration.GetSection("DatasulSeqSettings").Bind(datasulSeqSettings); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(Configuration) .Enrich.FromLogContext() .MinimumLevel.Debug() .Filter.ByExcluding("RequestPath = '/hc' and StatusCode = 200") .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning) .WriteTo.Debug() .WriteTo.Seq(datasulSeqSettings.Url) .WriteTo.File( datasulSeqSettings.FilePath, fileSizeLimitBytes: 1_000_000, rollOnFileSizeLimit: true, shared: true, flushToDiskInterval: TimeSpan.FromSeconds(1)) .WriteTo.ColoredConsole(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}") .CreateLogger(); try { Log.Information("Getting the motors running..."); CreateHostBuilder(args).Build().Run(); } catch (Exception ex) { Log.Fatal(ex, "Host terminated unexpectedly"); } finally { Log.CloseAndFlush(); } }