Skip to content

Commit d6dc82b

Browse files
Update samples (#1903)
* Remove redundant AspNetCore5 sample * Update sample csproj files * Update NLog sample for NLog breaking changes * Update ME Logging sample * Update Serilog AspNetCore sample
1 parent 5693b9b commit d6dc82b

File tree

34 files changed

+122
-426
lines changed

34 files changed

+122
-426
lines changed

Sentry.sln

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.NLog.Tests", "test\S
8383
EndProject
8484
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Samples.NLog", "samples\Sentry.Samples.NLog\Sentry.Samples.NLog.csproj", "{DC90D63E-E4F3-40CB-AF6D-2EAEE5F619B7}"
8585
EndProject
86-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Samples.AspNetCore5.Mvc", "samples\Sentry.Samples.AspNetCore5.Mvc\Sentry.Samples.AspNetCore5.Mvc.csproj", "{3CCB5D82-1D19-4FDE-B92D-CA726C418171}"
87-
EndProject
8886
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.AspNet", "src\Sentry.AspNet\Sentry.AspNet.csproj", "{22AA261A-F8B4-41E2-95DD-82632EED0AA5}"
8987
EndProject
9088
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.AspNet.Tests", "test\Sentry.AspNet.Tests\Sentry.AspNet.Tests.csproj", "{0885DDFE-2FC7-4241-AEB1-8D6BDA627C0A}"
@@ -257,10 +255,6 @@ Global
257255
{DC90D63E-E4F3-40CB-AF6D-2EAEE5F619B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
258256
{DC90D63E-E4F3-40CB-AF6D-2EAEE5F619B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
259257
{DC90D63E-E4F3-40CB-AF6D-2EAEE5F619B7}.Release|Any CPU.Build.0 = Release|Any CPU
260-
{3CCB5D82-1D19-4FDE-B92D-CA726C418171}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
261-
{3CCB5D82-1D19-4FDE-B92D-CA726C418171}.Debug|Any CPU.Build.0 = Debug|Any CPU
262-
{3CCB5D82-1D19-4FDE-B92D-CA726C418171}.Release|Any CPU.ActiveCfg = Release|Any CPU
263-
{3CCB5D82-1D19-4FDE-B92D-CA726C418171}.Release|Any CPU.Build.0 = Release|Any CPU
264258
{22AA261A-F8B4-41E2-95DD-82632EED0AA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
265259
{22AA261A-F8B4-41E2-95DD-82632EED0AA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
266260
{22AA261A-F8B4-41E2-95DD-82632EED0AA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -397,7 +391,6 @@ Global
397391
{998AC5A8-8D13-46EA-B889-8A733CA152F7} = {AF6AF4C7-8AA2-4D59-8064-2D79560904EB}
398392
{21A360C7-338F-4A9D-A9A3-83152D0C9303} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
399393
{DC90D63E-E4F3-40CB-AF6D-2EAEE5F619B7} = {77454495-55EE-4B40-A089-71B9E8F82E89}
400-
{3CCB5D82-1D19-4FDE-B92D-CA726C418171} = {77454495-55EE-4B40-A089-71B9E8F82E89}
401394
{22AA261A-F8B4-41E2-95DD-82632EED0AA5} = {AF6AF4C7-8AA2-4D59-8064-2D79560904EB}
402395
{0885DDFE-2FC7-4241-AEB1-8D6BDA627C0A} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
403396
{3454831A-397C-4039-AAFC-9152A4E0B682} = {9D7E2F87-D6F4-4BBB-8980-87D0A8344C74}

samples/Sentry.Samples.AspNetCore.Basic/Sentry.Samples.AspNetCore.Basic.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

samples/Sentry.Samples.AspNetCore.Blazor.Wasm/Sentry.Samples.AspNetCore.Blazor.Wasm.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.1" />
9-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.1" PrivateAssets="all" />
8+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.8" />
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.8" PrivateAssets="all" />
1010
<ProjectReference Include="..\..\src\Sentry\Sentry.csproj" />
1111
<ProjectReference Include="..\..\src\Sentry.Extensions.Logging\Sentry.Extensions.Logging.csproj" />
1212
</ItemGroup>

samples/Sentry.Samples.AspNetCore.Grpc/Sentry.Samples.AspNetCore.Grpc.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.40.0" />
9-
<PackageReference Include="Grpc.AspNetCore.Server.Reflection" Version="2.40.0" />
10-
<PackageReference Include="Grpc.Tools" Version="2.41.1" PrivateAssets="All" />
8+
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.48.0" />
9+
<PackageReference Include="Grpc.AspNetCore.Server.Reflection" Version="2.48.0" />
10+
<PackageReference Include="Grpc.Tools" Version="2.48.1" PrivateAssets="All" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

samples/Sentry.Samples.AspNetCore.Mvc/Sentry.Samples.AspNetCore.Mvc.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<RootNamespace>Samples.AspNetCore.Mvc</RootNamespace>
66
</PropertyGroup>
77

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,77 @@
1-
using Microsoft.AspNetCore;
21
using Serilog;
32
using Serilog.Events;
43

54
namespace Sentry.Samples.AspNetCore.Serilog;
65

76
public class Program
87
{
9-
public static void Main(string[] args) => BuildWebHost(args).Run();
8+
public static void Main(string[] args) => BuildWebApp(args).Run();
109

11-
public static IWebHost BuildWebHost(string[] args) =>
12-
WebHost.CreateDefaultBuilder(args)
13-
14-
.UseSerilog((_, c) =>
15-
c.Enrich.FromLogContext()
16-
.MinimumLevel.Debug()
17-
.WriteTo.Console()
18-
// Add Sentry integration with Serilog
19-
// Two levels are used to configure it.
20-
// One sets which log level is minimally required to keep a log message as breadcrumbs
21-
// The other sets the minimum level for messages to be sent out as events to Sentry
22-
.WriteTo.Sentry(s =>
23-
{
24-
s.MinimumBreadcrumbLevel = LogEventLevel.Debug;
25-
s.MinimumEventLevel = LogEventLevel.Error;
26-
}))
10+
public static WebApplication BuildWebApp(string[] args)
11+
{
12+
var builder = WebApplication.CreateBuilder(args);
13+
builder.Host.UseSerilog((_, c) =>
14+
c.Enrich.FromLogContext()
15+
.MinimumLevel.Debug()
16+
.WriteTo.Console()
17+
// Add Sentry integration with Serilog
18+
// Two levels are used to configure it.
19+
// One sets which log level is minimally required to keep a log message as breadcrumbs
20+
// The other sets the minimum level for messages to be sent out as events to Sentry
21+
.WriteTo.Sentry(s =>
22+
{
23+
s.MinimumBreadcrumbLevel = LogEventLevel.Debug;
24+
s.MinimumEventLevel = LogEventLevel.Error;
25+
}));
2726

28-
// Add Sentry integration
29-
// It can also be defined via configuration (including appsettings.json)
30-
// or coded explicitly, via parameter like:
31-
// .UseSentry("dsn") or .UseSentry(o => o.Dsn = ""; o.Release = "1.0"; ...)
32-
.UseSentry()
27+
// Add Sentry integration
28+
// It can also be defined via configuration (including appsettings.json)
29+
// or coded explicitly, via parameter like:
30+
// .UseSentry("dsn") or .UseSentry(o => o.Dsn = ""; o.Release = "1.0"; ...)
31+
builder.WebHost.UseSentry();
3332

34-
// The App:
35-
.Configure(a =>
33+
// The App:
34+
builder.WebHost.Configure(a =>
35+
{
36+
// An example ASP.NET Core middleware that throws an
37+
// exception when serving a request to path: /throw
38+
a.Use(async (context, next) =>
3639
{
37-
// An example ASP.NET Core middleware that throws an
38-
// exception when serving a request to path: /throw
39-
a.Use(async (context, next) =>
40-
{
41-
// See MinimumBreadcrumbLevel set at the Serilog configuration above
42-
Log.Logger.Debug("Static Serilog logger debug log stored as breadcrumbs.");
40+
// See MinimumBreadcrumbLevel set at the Serilog configuration above
41+
Log.Logger.Debug("Static Serilog logger debug log stored as breadcrumbs.");
4342

44-
var log = context.RequestServices.GetService<ILoggerFactory>()
45-
.CreateLogger<Program>();
43+
var log = context.RequestServices.GetRequiredService<ILoggerFactory>()
44+
.CreateLogger<Program>();
4645

47-
log.LogInformation("Handling some request...");
46+
log.LogInformation("Handling some request...");
4847

49-
// Sends an event which includes the info and debug messages above
50-
Log.Logger.Error("Logging using static Serilog directly also goes to Sentry.");
48+
// Sends an event which includes the info and debug messages above
49+
Log.Logger.Error("Logging using static Serilog directly also goes to Sentry.");
5150

52-
if (context.Request.Path == "/throw")
51+
if (context.Request.Path == "/throw")
52+
{
53+
var hub = context.RequestServices.GetRequiredService<IHub>();
54+
hub.ConfigureScope(s =>
5355
{
54-
var hub = context.RequestServices.GetService<IHub>();
55-
hub.ConfigureScope(s =>
56-
{
57-
// More data can be added to the scope like this:
58-
s.SetTag("Sample", "ASP.NET Core"); // indexed by Sentry
59-
s.SetExtra("Extra!", "Some extra information");
60-
});
56+
// More data can be added to the scope like this:
57+
s.SetTag("Sample", "ASP.NET Core"); // indexed by Sentry
58+
s.SetExtra("Extra!", "Some extra information");
59+
});
60+
61+
// Logging through the ASP.NET Core `ILogger` while using Serilog
62+
log.LogInformation("Logging info...");
63+
log.LogWarning("Logging some warning!");
6164

62-
// Logging through the ASP.NET Core `ILogger` while using Serilog
63-
log.LogInformation("Logging info...");
64-
log.LogWarning("Logging some warning!");
65+
// The following exception will be captured by the SDK and the event
66+
// will include the Log messages and any custom scope modifications
67+
// as exemplified above.
68+
throw new Exception("An exception thrown from the ASP.NET Core pipeline");
69+
}
6570

66-
// The following exception will be captured by the SDK and the event
67-
// will include the Log messages and any custom scope modifications
68-
// as exemplified above.
69-
throw new Exception("An exception thrown from the ASP.NET Core pipeline");
70-
}
71+
await next();
72+
});
73+
});
7174

72-
await next();
73-
});
74-
})
75-
.Build();
75+
return builder.Build();
76+
}
7677
}

samples/Sentry.Samples.AspNetCore.Serilog/Sentry.Samples.AspNetCore.Serilog.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.2" />
9-
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
10-
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
8+
<PackageReference Include="Serilog" Version="2.11.0" />
9+
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
10+
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

samples/Sentry.Samples.AspNetCore5.Mvc/Controllers/HomeController.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.

samples/Sentry.Samples.AspNetCore5.Mvc/Models/ErrorViewModel.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

samples/Sentry.Samples.AspNetCore5.Mvc/Program.cs

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)