Skip to content

Commit 3f3c5a9

Browse files
Configure Viewer Serilog from appsettings with console and file sinks
1 parent 7f7f208 commit 3f3c5a9

File tree

3 files changed

+58
-18
lines changed

3 files changed

+58
-18
lines changed

SysML2.NET.Viewer/Program.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ namespace SysML2.NET.Viewer
3535

3636
using Radzen;
3737

38-
using Serilog;
39-
using Serilog.Events;
38+
using Serilog;
4039

4140
using SySML2.NET.REST;
4241
using SysML2.NET.Serializer.Json;
@@ -55,18 +54,16 @@ public static class Program
5554
/// <returns>
5655
/// an awaitable <see cref="Task"/>
5756
/// </returns>
58-
public static async Task Main(string[] args)
59-
{
60-
Log.Logger = new LoggerConfiguration()
61-
.MinimumLevel.Debug()
62-
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
63-
.Enrich.FromLogContext()
64-
.WriteTo.BrowserConsole()
65-
.CreateLogger();
66-
67-
var builder = WebAssemblyHostBuilder.CreateDefault(args);
68-
builder.Services.AddLogging(loggingBuilder =>
69-
loggingBuilder.AddSerilog(dispose: true));
57+
public static async Task Main(string[] args)
58+
{
59+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
60+
61+
Log.Logger = new LoggerConfiguration()
62+
.ReadFrom.Configuration(builder.Configuration)
63+
.CreateLogger();
64+
65+
builder.Services.AddLogging(loggingBuilder =>
66+
loggingBuilder.AddSerilog(dispose: true));
7067

7168
builder.RootComponents.Add<App>("#app");
7269
builder.RootComponents.Add<HeadOutlet>("head::after");

SysML2.NET.Viewer/SysML2.NET.Viewer.csproj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@
2323
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.13" />
2424
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.13" PrivateAssets="all" />
2525
<PackageReference Include="ReactiveUI" Version="22.3.1" />
26-
<PackageReference Include="Radzen.Blazor" Version="9.0.4" />
27-
<PackageReference Include="Serilog.Extensions.Logging" Version="10.0.0" />
28-
<PackageReference Include="Serilog.Sinks.BrowserConsole" Version="8.0.0" />
29-
</ItemGroup>
26+
<PackageReference Include="Radzen.Blazor" Version="9.0.4" />
27+
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
28+
<PackageReference Include="Serilog.Enrichers.Process" Version="3.0.0" />
29+
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
30+
<PackageReference Include="Serilog.Extensions.Logging" Version="10.0.0" />
31+
<PackageReference Include="Serilog.Settings.Configuration" Version="10.0.0" />
32+
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
33+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
34+
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
35+
</ItemGroup>
3036

3137
<ItemGroup>
3238
<Folder Include="ViewModels\Pages\" />
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"Serilog": {
3+
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.Async" ],
4+
"MinimumLevel": {
5+
"Default": "Information",
6+
"Override": {
7+
"Microsoft": "Warning",
8+
"System": "Warning"
9+
}
10+
},
11+
"WriteTo": [
12+
{
13+
"Name": "Console"
14+
},
15+
{
16+
"Name": "Async",
17+
"Args": {
18+
"configure": [
19+
{
20+
"Name": "File",
21+
"Args": {
22+
"path": "logs/log-reqifviewer-.txt",
23+
"rollingInterval": "Day",
24+
"rollOnFileSizeLimit": true
25+
}
26+
}
27+
]
28+
}
29+
}
30+
],
31+
"Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId" ],
32+
"Properties": {
33+
"Application": "dmap-cdao",
34+
"Environment": "Production"
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)