/// <summary> /// Add Serilog bootstrap /// </summary> /// <param name="configuration"></param> /// <param name="serviceProvider"></param> /// <returns></returns> public static LoggerConfiguration AddSerilogBootstrapper( this LoggerConfiguration configuration, IServiceProvider serviceProvider ) { SelfLog.Enable(msg => Debug.WriteLine(msg)); var hostEnvironment = serviceProvider.GetRequiredService <IHostEnvironment>(); var botConfig = serviceProvider.GetRequiredService <IOptions <BotConfig> >().Value; var datadogConfig = serviceProvider.GetRequiredService <IOptions <DataDogConfig> >().Value; var eventLogConfig = serviceProvider.GetRequiredService <IOptions <EventLogConfig> >().Value; var exceptionLessConfig = serviceProvider.GetRequiredService <IOptions <ExceptionlessConfig> >().Value; var newRelicConfig = serviceProvider.GetRequiredService <IOptions <NewRelicConfig> >().Value; var grafanaConfig = serviceProvider.GetRequiredService <IOptions <GrafanaConfig> >().Value; var tgBotConfig = serviceProvider.GetRequiredService <IOptions <TgBotConfig> >().Value; var sentryConfig = serviceProvider.GetRequiredService <IOptions <SentryConfig> >().Value; eventLogConfig.TgBotConfig = tgBotConfig; configuration .Enrich.FromLogContext() // .Enrich.WithThreadId() // .Enrich.WithMemoryUsage(true) .MinimumLevel.Override( "Hangfire", LogEventLevel.Information ) .MinimumLevel.Override( "MySqlConnector", LogEventLevel.Information ) // .Filter.ByExcluding("{@m} not like '%pinged server%'") .WriteTo.Async( a => a.File( LogPath, rollingInterval: RollingInterval, flushToDiskInterval: FlushInterval, shared: true, outputTemplate: OutputTemplate ) ) .WriteTo.Async( a => a.Console( theme: SystemConsoleTheme.Colored, outputTemplate: OutputTemplate ) ); if (hostEnvironment.IsProduction()) { configuration.MinimumLevel.Information(); } else { configuration.MinimumLevel.Debug(); } configuration.AddDatadog(datadogConfig); configuration.AddGrafana(grafanaConfig); configuration.AddSentry(sentryConfig); configuration.AddTelegramBot4EventLog(eventLogConfig); configuration.AddExceptionless(exceptionLessConfig); configuration.AddNewRelic(newRelicConfig); return(configuration); }