Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
phongnguyend committed Jun 17, 2024
1 parent 0c81b7f commit eab38fb
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 307 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
},
"File": {
"MinimumLogEventLevel": "Debug"
},
"Elasticsearch": {
"IsEnabled": false,
"Host": "http://localhost:9200",
"IndexFormat": "classifiedads",
"MinimumLogEventLevel": "Debug"
}
},
"Caching": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.3.0" />
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="9.0.3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using System.Collections.Generic;

namespace ClassifiedAds.Infrastructure.Logging
{
public class LoggingOptions
{
public Dictionary<string, string> LogLevel { get; set; }
namespace ClassifiedAds.Infrastructure.Logging;

public FileOptions File { get; set; }
public class LoggingOptions
{
public Dictionary<string, string> 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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
},
"File": {
"MinimumLogEventLevel": "Debug"
},
"Elasticsearch": {
"IsEnabled": false,
"Host": "http://localhost:9200",
"IndexFormat": "classifiedads",
"MinimumLogEventLevel": "Debug"
}
},
"Caching": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageReference Include="Serilog.Exceptions" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="8.4.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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();
}

Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit eab38fb

Please sign in to comment.