From eab38fb6d69f8cb75cdfb5c3351c044311512fb7 Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Mon, 17 Jun 2024 16:36:47 +0700 Subject: [PATCH] remove unused code --- .../appsettings.json | 6 - .../ClassifiedAds.Infrastructure.csproj | 1 - .../Logging/ElasticsearchOptions.cs | 15 - .../Logging/LoggingExtensions.cs | 378 ++++++++---------- .../Logging/LoggingOptions.cs | 17 +- .../appsettings.json | 6 - .../ClassifiedAds.Infrastructure.csproj | 1 - .../Logging/ElasticsearchOptions.cs | 15 - .../Logging/LoggingExtensions.cs | 47 +-- .../Logging/LoggingOptions.cs | 2 - 10 files changed, 181 insertions(+), 307 deletions(-) delete mode 100644 src/IdentityServer/Duende/ClassifiedAds.Infrastructure/Logging/ElasticsearchOptions.cs delete mode 100644 src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/Logging/ElasticsearchOptions.cs diff --git a/src/IdentityServer/Duende/ClassifiedAds.IdentityServer/appsettings.json b/src/IdentityServer/Duende/ClassifiedAds.IdentityServer/appsettings.json index 41694ae46..da2649ce7 100644 --- a/src/IdentityServer/Duende/ClassifiedAds.IdentityServer/appsettings.json +++ b/src/IdentityServer/Duende/ClassifiedAds.IdentityServer/appsettings.json @@ -19,12 +19,6 @@ }, "File": { "MinimumLogEventLevel": "Debug" - }, - "Elasticsearch": { - "IsEnabled": false, - "Host": "http://localhost:9200", - "IndexFormat": "classifiedads", - "MinimumLogEventLevel": "Debug" } }, "Caching": { diff --git a/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj b/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj index 3cbae3be8..a90558882 100644 --- a/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj +++ b/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj @@ -36,7 +36,6 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/Logging/ElasticsearchOptions.cs b/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/Logging/ElasticsearchOptions.cs deleted file mode 100644 index 3465757f4..000000000 --- a/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/Logging/ElasticsearchOptions.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Serilog.Events; - -namespace ClassifiedAds.Infrastructure.Logging -{ - public class ElasticsearchOptions - { - public bool IsEnabled { get; set; } - - public string Host { get; set; } - - public string IndexFormat { get; set; } - - public LogEventLevel MinimumLogEventLevel { get; set; } - } -} diff --git a/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/Logging/LoggingExtensions.cs b/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/Logging/LoggingExtensions.cs index fe02c0c7c..b3c3231a3 100644 --- a/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/Logging/LoggingExtensions.cs +++ b/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/Logging/LoggingExtensions.cs @@ -5,257 +5,223 @@ using Microsoft.Extensions.Logging.EventLog; using Serilog; using Serilog.Exceptions; -using Serilog.Formatting.Json; -using Serilog.Sinks.Elasticsearch; -using Serilog.Sinks.File; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; -namespace ClassifiedAds.Infrastructure.Logging +namespace ClassifiedAds.Infrastructure.Logging; + +public static class LoggingExtensions { - public static class LoggingExtensions + private static void UseClassifiedAdsLogger(this IWebHostEnvironment env, LoggingOptions options) { - private static void UseClassifiedAdsLogger(this IWebHostEnvironment env, LoggingOptions options) - { - var assemblyName = Assembly.GetEntryAssembly()?.GetName().Name; - - var logsPath = Path.Combine(env.ContentRootPath, "logs"); - Directory.CreateDirectory(logsPath); - var loggerConfiguration = new LoggerConfiguration(); - - loggerConfiguration = loggerConfiguration - .MinimumLevel.Debug() - .Enrich.FromLogContext() - .Enrich.With() - .Enrich.WithMachineName() - .Enrich.WithEnvironmentUserName() - .Enrich.WithProperty("Assembly", assemblyName) - .Enrich.WithProperty("Application", env.ApplicationName) - .Enrich.WithProperty("EnvironmentName", env.EnvironmentName) - .Enrich.WithProperty("ContentRootPath", env.ContentRootPath) - .Enrich.WithProperty("WebRootPath", env.WebRootPath) - .Enrich.WithExceptionDetails() - .Filter.ByIncludingOnly((logEvent) => - { - if (logEvent.Level >= options.File.MinimumLogEventLevel - || logEvent.Level >= options.Elasticsearch.MinimumLogEventLevel) - { - var sourceContext = logEvent.Properties.ContainsKey("SourceContext") - ? logEvent.Properties["SourceContext"].ToString() - : null; - - var logLevel = GetLogLevel(sourceContext, options); - - return logEvent.Level >= logLevel; - } - - return false; - }) - .WriteTo.File(Path.Combine(logsPath, "log.txt"), - fileSizeLimitBytes: 10 * 1024 * 1024, - rollOnFileSizeLimit: true, - shared: true, - flushToDiskInterval: TimeSpan.FromSeconds(1), - outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{SourceContext}] [TraceId: {TraceId}] {Message:lj}{NewLine}{Exception}", - restrictedToMinimumLevel: options.File.MinimumLogEventLevel); - - if (options.Elasticsearch != null && options.Elasticsearch.IsEnabled) + var assemblyName = Assembly.GetEntryAssembly()?.GetName().Name; + + var logsPath = Path.Combine(env.ContentRootPath, "logs"); + Directory.CreateDirectory(logsPath); + var loggerConfiguration = new LoggerConfiguration(); + + loggerConfiguration = loggerConfiguration + .MinimumLevel.Debug() + .Enrich.FromLogContext() + .Enrich.WithMachineName() + .Enrich.WithEnvironmentUserName() + .Enrich.WithProperty("ProcessId", Environment.ProcessId) + .Enrich.WithProperty("Assembly", assemblyName) + .Enrich.WithProperty("Application", env.ApplicationName) + .Enrich.WithProperty("EnvironmentName", env.EnvironmentName) + .Enrich.WithProperty("ContentRootPath", env.ContentRootPath) + .Enrich.WithProperty("WebRootPath", env.WebRootPath) + .Enrich.WithExceptionDetails() + .Filter.ByIncludingOnly((logEvent) => { - loggerConfiguration = loggerConfiguration - .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(options.Elasticsearch.Host)) - { - MinimumLogEventLevel = options.Elasticsearch.MinimumLogEventLevel, - AutoRegisterTemplate = true, - AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6, - IndexFormat = options.Elasticsearch.IndexFormat + "-{0:yyyy.MM.dd}", - // BufferBaseFilename = Path.Combine(env.ContentRootPath, "logs", "buffer"), - InlineFields = true, - EmitEventFailure = EmitEventFailureHandling.WriteToFailureSink, - FailureSink = new FileSink(Path.Combine(logsPath, "elasticsearch-failures.txt"), new JsonFormatter(), null), - }); - } + if (logEvent.Level >= options.File.MinimumLogEventLevel) + { + var sourceContext = logEvent.Properties.ContainsKey("SourceContext") + ? logEvent.Properties["SourceContext"].ToString() + : null; - Log.Logger = loggerConfiguration.CreateLogger(); - } + var logLevel = GetLogLevel(sourceContext, options); - private static LoggingOptions SetDefault(LoggingOptions options) - { - options ??= new LoggingOptions - { - }; - - options.LogLevel ??= new Dictionary(); + return logEvent.Level >= logLevel; + } - if (!options.LogLevel.ContainsKey("Default")) - { - options.LogLevel["Default"] = "Warning"; - } + return false; + }) + .WriteTo.File(Path.Combine(logsPath, "log.txt"), + fileSizeLimitBytes: 10 * 1024 * 1024, + rollOnFileSizeLimit: true, + shared: true, + flushToDiskInterval: TimeSpan.FromSeconds(1), + outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{SourceContext}] [TraceId: {TraceId}] [MachineName: {MachineName}] [ProcessId: {ProcessId}] {Message:lj}{NewLine}{Exception}", + restrictedToMinimumLevel: options.File.MinimumLogEventLevel); + + Log.Logger = loggerConfiguration.CreateLogger(); + } - options.File ??= new FileOptions - { - MinimumLogEventLevel = Serilog.Events.LogEventLevel.Warning, - }; + private static LoggingOptions SetDefault(LoggingOptions options) + { + options ??= new LoggingOptions + { + }; - options.Elasticsearch ??= new ElasticsearchOptions - { - IsEnabled = false, - MinimumLogEventLevel = Serilog.Events.LogEventLevel.Warning, - }; + options.LogLevel ??= new Dictionary(); - options.EventLog ??= new EventLogOptions - { - IsEnabled = false, - }; - return options; + if (!options.LogLevel.ContainsKey("Default")) + { + options.LogLevel["Default"] = "Warning"; } - private static Serilog.Events.LogEventLevel GetLogLevel(string context, LoggingOptions options) + options.File ??= new FileOptions { - context = context.Replace("\"", string.Empty); - string level = "Default"; - var matches = options.LogLevel.Keys.Where(k => context.StartsWith(k, StringComparison.OrdinalIgnoreCase)); + MinimumLogEventLevel = Serilog.Events.LogEventLevel.Warning, + }; - if (matches.Any()) - { - level = matches.Max(); - } + options.EventLog ??= new EventLogOptions + { + IsEnabled = false, + }; + return options; + } + + private static Serilog.Events.LogEventLevel GetLogLevel(string context, LoggingOptions options) + { + context = context.Replace("\"", string.Empty); + string level = "Default"; + var matches = options.LogLevel.Keys.Where(k => context.StartsWith(k, StringComparison.OrdinalIgnoreCase)); - return (Serilog.Events.LogEventLevel)Enum.Parse(typeof(Serilog.Events.LogEventLevel), options.LogLevel[level], true); + if (matches.Any()) + { + level = matches.Max(); } - public static IWebHostBuilder UseClassifiedAdsLogger(this IWebHostBuilder builder, Func logOptions) + return (Serilog.Events.LogEventLevel)Enum.Parse(typeof(Serilog.Events.LogEventLevel), options.LogLevel[level], true); + } + + public static IWebHostBuilder UseClassifiedAdsLogger(this IWebHostBuilder builder, Func logOptions) + { + builder.ConfigureLogging((context, logging) => { - builder.ConfigureLogging((context, logging) => + logging.Configure(options => { - logging.Configure(options => - { - // options.ActivityTrackingOptions = ActivityTrackingOptions.SpanId | ActivityTrackingOptions.TraceId | ActivityTrackingOptions.ParentId; - }); + // options.ActivityTrackingOptions = ActivityTrackingOptions.SpanId | ActivityTrackingOptions.TraceId | ActivityTrackingOptions.ParentId; + }); - logging.AddAzureWebAppDiagnostics(); + logging.AddAzureWebAppDiagnostics(); - logging.AddSerilog(); + logging.AddSerilog(); - LoggingOptions options = SetDefault(logOptions(context.Configuration)); + LoggingOptions options = SetDefault(logOptions(context.Configuration)); - if (options.EventLog != null && options.EventLog.IsEnabled) + if (options.EventLog != null && options.EventLog.IsEnabled && OperatingSystem.IsWindows()) + { + logging.AddEventLog(new EventLogSettings { - logging.AddEventLog(new EventLogSettings - { - LogName = options.EventLog.LogName, - SourceName = options.EventLog.SourceName, - }); - } + LogName = options.EventLog.LogName, + SourceName = options.EventLog.SourceName, + }); + } - if (options?.ApplicationInsights?.IsEnabled ?? false) - { - logging.AddApplicationInsights(options.ApplicationInsights.InstrumentationKey); - } + if (options?.ApplicationInsights?.IsEnabled ?? false) + { + logging.AddApplicationInsights( + configureTelemetryConfiguration: (config) => + { + config.ConnectionString = options.ApplicationInsights.InstrumentationKey; + }, + configureApplicationInsightsLoggerOptions: (options) => { }); + } - context.HostingEnvironment.UseClassifiedAdsLogger(options); - }); + context.HostingEnvironment.UseClassifiedAdsLogger(options); + }); - return builder; - } + return builder; + } - public static IHostBuilder UseClassifiedAdsLogger(this IHostBuilder builder, Func logOptions) + public static IHostBuilder UseClassifiedAdsLogger(this IHostBuilder builder, Func logOptions) + { + builder.ConfigureLogging((context, logging) => { - builder.ConfigureLogging((context, logging) => + logging.Configure(options => { - logging.Configure(options => - { - // options.ActivityTrackingOptions = ActivityTrackingOptions.SpanId | ActivityTrackingOptions.TraceId | ActivityTrackingOptions.ParentId; - }); + // options.ActivityTrackingOptions = ActivityTrackingOptions.SpanId | ActivityTrackingOptions.TraceId | ActivityTrackingOptions.ParentId; + }); - logging.AddAzureWebAppDiagnostics(); + logging.AddAzureWebAppDiagnostics(); - logging.AddSerilog(); + logging.AddSerilog(); - LoggingOptions options = SetDefault(logOptions(context.Configuration)); + LoggingOptions options = SetDefault(logOptions(context.Configuration)); - if (options.EventLog != null && options.EventLog.IsEnabled) + if (options.EventLog != null && options.EventLog.IsEnabled && OperatingSystem.IsWindows()) + { + logging.AddEventLog(new EventLogSettings { - logging.AddEventLog(new EventLogSettings - { - LogName = options.EventLog.LogName, - SourceName = options.EventLog.SourceName, - }); - } + LogName = options.EventLog.LogName, + SourceName = options.EventLog.SourceName, + }); + } - if (options?.ApplicationInsights?.IsEnabled ?? false) - { - logging.AddApplicationInsights(options.ApplicationInsights.InstrumentationKey); - } + if (options?.ApplicationInsights?.IsEnabled ?? false) + { + logging.AddApplicationInsights( + configureTelemetryConfiguration: (config) => + { + config.ConnectionString = options.ApplicationInsights.InstrumentationKey; + }, + configureApplicationInsightsLoggerOptions: (options) => { }); + } - context.HostingEnvironment.UseClassifiedAdsLogger(options); - }); + context.HostingEnvironment.UseClassifiedAdsLogger(options); + }); - return builder; - } + return builder; + } - private static void UseClassifiedAdsLogger(this IHostEnvironment env, LoggingOptions options) - { - var assemblyName = Assembly.GetEntryAssembly()?.GetName().Name; - - var logsPath = Path.Combine(env.ContentRootPath, "logs"); - Directory.CreateDirectory(logsPath); - var loggerConfiguration = new LoggerConfiguration(); - - loggerConfiguration = loggerConfiguration - .MinimumLevel.Debug() - .Enrich.FromLogContext() - .Enrich.With() - .Enrich.WithMachineName() - .Enrich.WithEnvironmentUserName() - .Enrich.WithProperty("Assembly", assemblyName) - .Enrich.WithProperty("Application", env.ApplicationName) - .Enrich.WithProperty("EnvironmentName", env.EnvironmentName) - .Enrich.WithProperty("ContentRootPath", env.ContentRootPath) - .Enrich.WithExceptionDetails() - .Filter.ByIncludingOnly((logEvent) => - { - if (logEvent.Level >= options.File.MinimumLogEventLevel - || logEvent.Level >= options.Elasticsearch.MinimumLogEventLevel) - { - var sourceContext = logEvent.Properties.ContainsKey("SourceContext") - ? logEvent.Properties["SourceContext"].ToString() - : null; - - var logLevel = GetLogLevel(sourceContext, options); - - return logEvent.Level >= logLevel; - } - - return false; - }) - .WriteTo.File(Path.Combine(logsPath, "log.txt"), - fileSizeLimitBytes: 10 * 1024 * 1024, - rollOnFileSizeLimit: true, - shared: true, - flushToDiskInterval: TimeSpan.FromSeconds(1), - outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{SourceContext}] [TraceId: {TraceId}] {Message:lj}{NewLine}{Exception}", - restrictedToMinimumLevel: options.File.MinimumLogEventLevel); - - if (options.Elasticsearch != null && options.Elasticsearch.IsEnabled) + private static void UseClassifiedAdsLogger(this IHostEnvironment env, LoggingOptions options) + { + var assemblyName = Assembly.GetEntryAssembly()?.GetName().Name; + + var logsPath = Path.Combine(env.ContentRootPath, "logs"); + Directory.CreateDirectory(logsPath); + var loggerConfiguration = new LoggerConfiguration(); + + loggerConfiguration = loggerConfiguration + .MinimumLevel.Debug() + .Enrich.FromLogContext() + .Enrich.WithMachineName() + .Enrich.WithEnvironmentUserName() + .Enrich.WithProperty("ProcessId", Environment.ProcessId) + .Enrich.WithProperty("Assembly", assemblyName) + .Enrich.WithProperty("Application", env.ApplicationName) + .Enrich.WithProperty("EnvironmentName", env.EnvironmentName) + .Enrich.WithProperty("ContentRootPath", env.ContentRootPath) + .Enrich.WithExceptionDetails() + .Filter.ByIncludingOnly((logEvent) => { - loggerConfiguration = loggerConfiguration - .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(options.Elasticsearch.Host)) - { - MinimumLogEventLevel = options.Elasticsearch.MinimumLogEventLevel, - AutoRegisterTemplate = true, - AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6, - IndexFormat = options.Elasticsearch.IndexFormat + "-{0:yyyy.MM.dd}", - // BufferBaseFilename = Path.Combine(env.ContentRootPath, "logs", "buffer"), - InlineFields = true, - EmitEventFailure = EmitEventFailureHandling.WriteToFailureSink, - FailureSink = new FileSink(Path.Combine(logsPath, "elasticsearch-failures.txt"), new JsonFormatter(), null), - }); - } + if (logEvent.Level >= options.File.MinimumLogEventLevel) + { + var sourceContext = logEvent.Properties.ContainsKey("SourceContext") + ? logEvent.Properties["SourceContext"].ToString() + : null; - Log.Logger = loggerConfiguration.CreateLogger(); - } + var logLevel = GetLogLevel(sourceContext, options); + + return logEvent.Level >= logLevel; + } + + return false; + }) + .WriteTo.File(Path.Combine(logsPath, "log.txt"), + fileSizeLimitBytes: 10 * 1024 * 1024, + rollOnFileSizeLimit: true, + shared: true, + flushToDiskInterval: TimeSpan.FromSeconds(1), + outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{SourceContext}] [TraceId: {TraceId}] [MachineName: {MachineName}] [ProcessId: {ProcessId}] {Message:lj}{NewLine}{Exception}", + restrictedToMinimumLevel: options.File.MinimumLogEventLevel); + + Log.Logger = loggerConfiguration.CreateLogger(); } } diff --git a/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/Logging/LoggingOptions.cs b/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/Logging/LoggingOptions.cs index ef51eac0f..7ba3d7e22 100644 --- a/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/Logging/LoggingOptions.cs +++ b/src/IdentityServer/Duende/ClassifiedAds.Infrastructure/Logging/LoggingOptions.cs @@ -1,17 +1,14 @@ using System.Collections.Generic; -namespace ClassifiedAds.Infrastructure.Logging -{ - public class LoggingOptions - { - public Dictionary LogLevel { get; set; } +namespace ClassifiedAds.Infrastructure.Logging; - public FileOptions File { get; set; } +public class LoggingOptions +{ + public Dictionary LogLevel { get; set; } - public ElasticsearchOptions Elasticsearch { get; set; } + public FileOptions File { get; set; } - public EventLogOptions EventLog { get; set; } + public EventLogOptions EventLog { get; set; } - public ApplicationInsightsOptions ApplicationInsights { get; set; } - } + public ApplicationInsightsOptions ApplicationInsights { get; set; } } diff --git a/src/IdentityServer/IdentityServer4/ClassifiedAds.IdentityServer/appsettings.json b/src/IdentityServer/IdentityServer4/ClassifiedAds.IdentityServer/appsettings.json index c6a36bdc8..2cc7fa013 100644 --- a/src/IdentityServer/IdentityServer4/ClassifiedAds.IdentityServer/appsettings.json +++ b/src/IdentityServer/IdentityServer4/ClassifiedAds.IdentityServer/appsettings.json @@ -19,12 +19,6 @@ }, "File": { "MinimumLogEventLevel": "Debug" - }, - "Elasticsearch": { - "IsEnabled": false, - "Host": "http://localhost:9200", - "IndexFormat": "classifiedads", - "MinimumLogEventLevel": "Debug" } }, "Caching": { diff --git a/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj b/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj index e59b76afe..60b5668b3 100644 --- a/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj +++ b/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj @@ -36,7 +36,6 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/Logging/ElasticsearchOptions.cs b/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/Logging/ElasticsearchOptions.cs deleted file mode 100644 index 3465757f4..000000000 --- a/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/Logging/ElasticsearchOptions.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Serilog.Events; - -namespace ClassifiedAds.Infrastructure.Logging -{ - public class ElasticsearchOptions - { - public bool IsEnabled { get; set; } - - public string Host { get; set; } - - public string IndexFormat { get; set; } - - public LogEventLevel MinimumLogEventLevel { get; set; } - } -} diff --git a/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/Logging/LoggingExtensions.cs b/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/Logging/LoggingExtensions.cs index fe02c0c7c..eb127fc60 100644 --- a/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/Logging/LoggingExtensions.cs +++ b/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/Logging/LoggingExtensions.cs @@ -5,9 +5,6 @@ using Microsoft.Extensions.Logging.EventLog; using Serilog; using Serilog.Exceptions; -using Serilog.Formatting.Json; -using Serilog.Sinks.Elasticsearch; -using Serilog.Sinks.File; using System; using System.Collections.Generic; using System.IO; @@ -40,8 +37,7 @@ private static void UseClassifiedAdsLogger(this IWebHostEnvironment env, Logging .Enrich.WithExceptionDetails() .Filter.ByIncludingOnly((logEvent) => { - if (logEvent.Level >= options.File.MinimumLogEventLevel - || logEvent.Level >= options.Elasticsearch.MinimumLogEventLevel) + if (logEvent.Level >= options.File.MinimumLogEventLevel) { var sourceContext = logEvent.Properties.ContainsKey("SourceContext") ? logEvent.Properties["SourceContext"].ToString() @@ -62,22 +58,6 @@ private static void UseClassifiedAdsLogger(this IWebHostEnvironment env, Logging outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{SourceContext}] [TraceId: {TraceId}] {Message:lj}{NewLine}{Exception}", restrictedToMinimumLevel: options.File.MinimumLogEventLevel); - if (options.Elasticsearch != null && options.Elasticsearch.IsEnabled) - { - loggerConfiguration = loggerConfiguration - .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(options.Elasticsearch.Host)) - { - MinimumLogEventLevel = options.Elasticsearch.MinimumLogEventLevel, - AutoRegisterTemplate = true, - AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6, - IndexFormat = options.Elasticsearch.IndexFormat + "-{0:yyyy.MM.dd}", - // BufferBaseFilename = Path.Combine(env.ContentRootPath, "logs", "buffer"), - InlineFields = true, - EmitEventFailure = EmitEventFailureHandling.WriteToFailureSink, - FailureSink = new FileSink(Path.Combine(logsPath, "elasticsearch-failures.txt"), new JsonFormatter(), null), - }); - } - Log.Logger = loggerConfiguration.CreateLogger(); } @@ -99,12 +79,6 @@ private static LoggingOptions SetDefault(LoggingOptions options) MinimumLogEventLevel = Serilog.Events.LogEventLevel.Warning, }; - options.Elasticsearch ??= new ElasticsearchOptions - { - IsEnabled = false, - MinimumLogEventLevel = Serilog.Events.LogEventLevel.Warning, - }; - options.EventLog ??= new EventLogOptions { IsEnabled = false, @@ -217,8 +191,7 @@ private static void UseClassifiedAdsLogger(this IHostEnvironment env, LoggingOpt .Enrich.WithExceptionDetails() .Filter.ByIncludingOnly((logEvent) => { - if (logEvent.Level >= options.File.MinimumLogEventLevel - || logEvent.Level >= options.Elasticsearch.MinimumLogEventLevel) + if (logEvent.Level >= options.File.MinimumLogEventLevel) { var sourceContext = logEvent.Properties.ContainsKey("SourceContext") ? logEvent.Properties["SourceContext"].ToString() @@ -239,22 +212,6 @@ private static void UseClassifiedAdsLogger(this IHostEnvironment env, LoggingOpt outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{SourceContext}] [TraceId: {TraceId}] {Message:lj}{NewLine}{Exception}", restrictedToMinimumLevel: options.File.MinimumLogEventLevel); - if (options.Elasticsearch != null && options.Elasticsearch.IsEnabled) - { - loggerConfiguration = loggerConfiguration - .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(options.Elasticsearch.Host)) - { - MinimumLogEventLevel = options.Elasticsearch.MinimumLogEventLevel, - AutoRegisterTemplate = true, - AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6, - IndexFormat = options.Elasticsearch.IndexFormat + "-{0:yyyy.MM.dd}", - // BufferBaseFilename = Path.Combine(env.ContentRootPath, "logs", "buffer"), - InlineFields = true, - EmitEventFailure = EmitEventFailureHandling.WriteToFailureSink, - FailureSink = new FileSink(Path.Combine(logsPath, "elasticsearch-failures.txt"), new JsonFormatter(), null), - }); - } - Log.Logger = loggerConfiguration.CreateLogger(); } } diff --git a/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/Logging/LoggingOptions.cs b/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/Logging/LoggingOptions.cs index ef51eac0f..e5e8ae23d 100644 --- a/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/Logging/LoggingOptions.cs +++ b/src/IdentityServer/IdentityServer4/ClassifiedAds.Infrastructure/Logging/LoggingOptions.cs @@ -8,8 +8,6 @@ public class LoggingOptions public FileOptions File { get; set; } - public ElasticsearchOptions Elasticsearch { get; set; } - public EventLogOptions EventLog { get; set; } public ApplicationInsightsOptions ApplicationInsights { get; set; }