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 7, 2024
1 parent b87a62c commit f3dd9e4
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
using OpenTelemetry.Trace;
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 @@ -43,8 +40,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 @@ -65,22 +61,6 @@ private static void UseClassifiedAdsLogger(this IWebHostEnvironment env, Logging
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);

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 @@ -102,12 +82,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 @@ -258,8 +232,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 @@ -280,22 +253,6 @@ private static void UseClassifiedAdsLogger(this IHostEnvironment env, LoggingOpt
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);

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();
}
}
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
6 changes: 0 additions & 6 deletions src/ModularMonolith/ClassifiedAds.WebAPI/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
"File": {
"MinimumLogEventLevel": "Information"
},
"Elasticsearch": {
"IsEnabled": false,
"Host": "http://localhost:9200",
"IndexFormat": "classifiedads",
"MinimumLogEventLevel": "Information"
},
"EventLog": {
"IsEnabled": false,
"LogName": "Application",
Expand Down

0 comments on commit f3dd9e4

Please sign in to comment.