Skip to content

Commit

Permalink
override updates
Browse files Browse the repository at this point in the history
  • Loading branch information
biplovkc committed Mar 14, 2023
1 parent 2d3b7f7 commit f2776cb
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/LoggingServiceCollectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,37 @@

public static class LoggingServiceCollectionExtension
{
public static IServiceCollection RegisterSerilogLogger(this IServiceCollection services, IConfiguration configuration, string version, Dictionary<string, LogEventLevel> overrides = null, params string[] pathsToExclude)
public static IServiceCollection RegisterSerilogLogger(this IServiceCollection services, IConfiguration configuration, string version, params string[] pathsToExclude)
{
var loggerConfig = new LoggerConfiguration()
.ReadFrom.Configuration(configuration);

var logger = loggerConfig
.Enrich.FromLogContext()
.Enrich.WithAssemblyName()
.Enrich.WithEnvironmentName()
.Enrich.WithSpan();

if (!string.IsNullOrWhiteSpace(version))
{
logger.Enrich.WithProperty("Version", version);
}

if (pathsToExclude.Any())
{
foreach (var path in pathsToExclude)
{
logger.Filter.ByExcluding(path);
}
}

Log.Logger = logger.CreateLogger();
services.AddSingleton(Log.Logger);

return services;
}

public static IServiceCollection RegisterSerilogLogger(this IServiceCollection services, IConfiguration configuration, string version, Dictionary<string, LogEventLevel> overrides, params string[] pathsToExclude)
{
var loggerConfig = new LoggerConfiguration()
.ReadFrom.Configuration(configuration);
Expand Down

0 comments on commit f2776cb

Please sign in to comment.