-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d70b17
commit 7f703b9
Showing
5 changed files
with
55 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Microsoft.Extensions.Hosting; | ||
using Serilog; | ||
using Serilog.Events; | ||
using Serilog.Exceptions; | ||
using Serilog.Sinks.SystemConsole.Themes; | ||
|
||
namespace DevNews.WebApp.Infrastructure | ||
{ | ||
public class SerilogOptions | ||
{ | ||
public bool ConsoleEnabled { get; set; } = true; | ||
public string MinimumLevel { get; set; } = "Information"; | ||
public string Format { get; set; } = "compact"; | ||
} | ||
|
||
public static class SerilogExtensions | ||
{ | ||
public static IHostBuilder UseLogger(this IHostBuilder hostBuilder, string applicationName = null) | ||
{ | ||
return hostBuilder.ConfigureLogging(builder => | ||
{ | ||
var conf = new LoggerConfiguration() | ||
.MinimumLevel.Is(LogEventLevel.Information) | ||
.Enrich.FromLogContext() | ||
.Enrich.WithProperty("ApplicationName", applicationName) | ||
.Enrich.WithEnvironmentUserName() | ||
.Enrich.WithProcessId() | ||
.Enrich.WithProcessName() | ||
.Enrich.WithThreadId() | ||
.Enrich.WithExceptionDetails(); | ||
|
||
conf.WriteTo.Console(theme: AnsiConsoleTheme.Code); | ||
conf.WriteTo.Trace(); | ||
builder.AddSerilog(conf.CreateLogger()); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
"ConnectionStrings": { | ||
"Articles": "mongodb://root:rootpassword@127.0.0.1:27017" | ||
}, | ||
"AllowedHosts": "*" | ||
"Serilog": { | ||
"MinimumLevel": "Information", | ||
"ConsoleEnabled": true, | ||
"Format": "colored" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Serilog.Enrichers.Environment | ||
Serilog.Enrichers.Process | ||
Serilog.Enrichers.Thread | ||
Serilog.Exceptions | ||
Serilog.Sinks.Async | ||
Serilog.Sinks.Trace | ||
Serilog.Sinks.Seq | ||
Serilog.Formatting.Elasticsearch | ||
Serilog.AspNetCore |