Skip to content

Commit 707a1a4

Browse files
committed
Migrate to Serilog for logging
1 parent 2171357 commit 707a1a4

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

Directory.Packages.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@
66
<ItemGroup>
77
<PackageVersion Include="Mindscape.Raygun4Net.AspNetCore" Version="11.2.1" />
88
<PackageVersion Include="Mindscape.Raygun4Net.NetCore.Common" Version="11.2.1" />
9+
<PackageVersion Include="Serilog" Version="4.3.0" />
10+
<PackageVersion Include="Serilog.AspNetCore" Version="7.0.0" />
11+
<PackageVersion Include="Serilog.Enrichers.Environment" Version="3.0.1" />
12+
<PackageVersion Include="Serilog.Enrichers.Thread" Version="4.0.0" />
13+
<PackageVersion Include="Serilog.Sinks.Raygun" Version="8.2.0" />
914
</ItemGroup>
1015
</Project>

src/Minigun/Minigun.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="Mindscape.Raygun4Net.AspNetCore"/>
13+
<PackageReference Include="Serilog" />
14+
<PackageReference Include="Serilog.Sinks.Raygun" />
15+
<PackageReference Include="Serilog.AspNetCore" />
16+
<PackageReference Include="Serilog.Enrichers.Environment" />
17+
<PackageReference Include="Serilog.Enrichers.Thread" />
1318
</ItemGroup>
1419

1520
<ItemGroup>

src/Minigun/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
using Mindscape.Raygun4Net.AspNetCore;
33
using Minigun.Middleware;
44
using Minigun.Services;
5+
using Serilog;
56

67
var builder = WebApplication.CreateBuilder(args);
78

9+
builder.Host.UseSerilog((context, configuration) => configuration.ReadFrom.Configuration(context.Configuration));
10+
811
builder.Services.AddControllersWithViews();
912

1013
builder.Services.AddHttpClient();
@@ -37,8 +40,6 @@
3740
app.UseHsts();
3841
}
3942

40-
app.UseRaygun();
41-
4243
app.UseRaygunPatMiddleware();
4344

4445
app.UseHttpsRedirection();

src/Minigun/appsettings.json

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
11
{
2+
"Serilog": {
3+
"Using": [
4+
"Serilog.Sinks.Console",
5+
"Serilog.Enrichers.Environment",
6+
"Serilog.Enrichers.Thread",
7+
"Serilog.Sinks.Raygun"
8+
],
9+
"MinimumLevel": {
10+
"Default": "Information",
11+
"Override": {
12+
"Microsoft.AspNetCore.Hosting.Diagnostics": "Information",
13+
"Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker": "Warning",
14+
"Microsoft.AspNetCore.Routing.DefaultLinkGenerator": "Information"
15+
}
16+
},
17+
"WriteTo": [
18+
{
19+
"Name": "Console"
20+
},
21+
{
22+
"Name": "Raygun",
23+
"Args": {
24+
"applicationKey": "#{RAYGUN_API_KEY}"
25+
}
26+
}
27+
],
28+
"Enrich": [
29+
"FromLogContext",
30+
"WithMachineName",
31+
"WithEnvironmentUserName",
32+
"WithEnvironmentName",
33+
"WithThreadId"
34+
]
35+
},
236
"Logging": {
337
"LogLevel": {
438
"Default": "Information",
539
"Microsoft.AspNetCore": "Warning"
640
}
741
},
8-
"RaygunSettings": {
9-
"ApiKey": "#{RAYGUN_API_KEY}"
10-
},
1142
"AllowedHosts": "*"
1243
}

0 commit comments

Comments
 (0)