Skip to content

Commit

Permalink
Update samples (#1903)
Browse files Browse the repository at this point in the history
* Remove redundant AspNetCore5 sample

* Update sample csproj files

* Update NLog sample for NLog breaking changes

* Update ME Logging sample

* Update Serilog AspNetCore sample
  • Loading branch information
mattjohnsonpint authored Sep 7, 2022
1 parent 5693b9b commit d6dc82b
Show file tree
Hide file tree
Showing 34 changed files with 122 additions and 426 deletions.
7 changes: 0 additions & 7 deletions Sentry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.NLog.Tests", "test\S
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Samples.NLog", "samples\Sentry.Samples.NLog\Sentry.Samples.NLog.csproj", "{DC90D63E-E4F3-40CB-AF6D-2EAEE5F619B7}"
EndProject
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}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.AspNet", "src\Sentry.AspNet\Sentry.AspNet.csproj", "{22AA261A-F8B4-41E2-95DD-82632EED0AA5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.AspNet.Tests", "test\Sentry.AspNet.Tests\Sentry.AspNet.Tests.csproj", "{0885DDFE-2FC7-4241-AEB1-8D6BDA627C0A}"
Expand Down Expand Up @@ -257,10 +255,6 @@ Global
{DC90D63E-E4F3-40CB-AF6D-2EAEE5F619B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC90D63E-E4F3-40CB-AF6D-2EAEE5F619B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC90D63E-E4F3-40CB-AF6D-2EAEE5F619B7}.Release|Any CPU.Build.0 = Release|Any CPU
{3CCB5D82-1D19-4FDE-B92D-CA726C418171}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3CCB5D82-1D19-4FDE-B92D-CA726C418171}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3CCB5D82-1D19-4FDE-B92D-CA726C418171}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3CCB5D82-1D19-4FDE-B92D-CA726C418171}.Release|Any CPU.Build.0 = Release|Any CPU
{22AA261A-F8B4-41E2-95DD-82632EED0AA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{22AA261A-F8B4-41E2-95DD-82632EED0AA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22AA261A-F8B4-41E2-95DD-82632EED0AA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -397,7 +391,6 @@ Global
{998AC5A8-8D13-46EA-B889-8A733CA152F7} = {AF6AF4C7-8AA2-4D59-8064-2D79560904EB}
{21A360C7-338F-4A9D-A9A3-83152D0C9303} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
{DC90D63E-E4F3-40CB-AF6D-2EAEE5F619B7} = {77454495-55EE-4B40-A089-71B9E8F82E89}
{3CCB5D82-1D19-4FDE-B92D-CA726C418171} = {77454495-55EE-4B40-A089-71B9E8F82E89}
{22AA261A-F8B4-41E2-95DD-82632EED0AA5} = {AF6AF4C7-8AA2-4D59-8064-2D79560904EB}
{0885DDFE-2FC7-4241-AEB1-8D6BDA627C0A} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
{3454831A-397C-4039-AAFC-9152A4E0B682} = {9D7E2F87-D6F4-4BBB-8980-87D0A8344C74}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.8" PrivateAssets="all" />
<ProjectReference Include="..\..\src\Sentry\Sentry.csproj" />
<ProjectReference Include="..\..\src\Sentry.Extensions.Logging\Sentry.Extensions.Logging.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.40.0" />
<PackageReference Include="Grpc.AspNetCore.Server.Reflection" Version="2.40.0" />
<PackageReference Include="Grpc.Tools" Version="2.41.1" PrivateAssets="All" />
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.48.0" />
<PackageReference Include="Grpc.AspNetCore.Server.Reflection" Version="2.48.0" />
<PackageReference Include="Grpc.Tools" Version="2.48.1" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Samples.AspNetCore.Mvc</RootNamespace>
</PropertyGroup>

Expand Down
113 changes: 57 additions & 56 deletions samples/Sentry.Samples.AspNetCore.Serilog/Program.cs
Original file line number Diff line number Diff line change
@@ -1,76 +1,77 @@
using Microsoft.AspNetCore;
using Serilog;
using Serilog.Events;

namespace Sentry.Samples.AspNetCore.Serilog;

public class Program
{
public static void Main(string[] args) => BuildWebHost(args).Run();
public static void Main(string[] args) => BuildWebApp(args).Run();

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)

.UseSerilog((_, c) =>
c.Enrich.FromLogContext()
.MinimumLevel.Debug()
.WriteTo.Console()
// Add Sentry integration with Serilog
// Two levels are used to configure it.
// One sets which log level is minimally required to keep a log message as breadcrumbs
// The other sets the minimum level for messages to be sent out as events to Sentry
.WriteTo.Sentry(s =>
{
s.MinimumBreadcrumbLevel = LogEventLevel.Debug;
s.MinimumEventLevel = LogEventLevel.Error;
}))
public static WebApplication BuildWebApp(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((_, c) =>
c.Enrich.FromLogContext()
.MinimumLevel.Debug()
.WriteTo.Console()
// Add Sentry integration with Serilog
// Two levels are used to configure it.
// One sets which log level is minimally required to keep a log message as breadcrumbs
// The other sets the minimum level for messages to be sent out as events to Sentry
.WriteTo.Sentry(s =>
{
s.MinimumBreadcrumbLevel = LogEventLevel.Debug;
s.MinimumEventLevel = LogEventLevel.Error;
}));

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

// The App:
.Configure(a =>
// The App:
builder.WebHost.Configure(a =>
{
// An example ASP.NET Core middleware that throws an
// exception when serving a request to path: /throw
a.Use(async (context, next) =>
{
// An example ASP.NET Core middleware that throws an
// exception when serving a request to path: /throw
a.Use(async (context, next) =>
{
// See MinimumBreadcrumbLevel set at the Serilog configuration above
Log.Logger.Debug("Static Serilog logger debug log stored as breadcrumbs.");
// See MinimumBreadcrumbLevel set at the Serilog configuration above
Log.Logger.Debug("Static Serilog logger debug log stored as breadcrumbs.");

var log = context.RequestServices.GetService<ILoggerFactory>()
.CreateLogger<Program>();
var log = context.RequestServices.GetRequiredService<ILoggerFactory>()
.CreateLogger<Program>();

log.LogInformation("Handling some request...");
log.LogInformation("Handling some request...");

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

if (context.Request.Path == "/throw")
if (context.Request.Path == "/throw")
{
var hub = context.RequestServices.GetRequiredService<IHub>();
hub.ConfigureScope(s =>
{
var hub = context.RequestServices.GetService<IHub>();
hub.ConfigureScope(s =>
{
// More data can be added to the scope like this:
s.SetTag("Sample", "ASP.NET Core"); // indexed by Sentry
s.SetExtra("Extra!", "Some extra information");
});
// More data can be added to the scope like this:
s.SetTag("Sample", "ASP.NET Core"); // indexed by Sentry
s.SetExtra("Extra!", "Some extra information");
});

// Logging through the ASP.NET Core `ILogger` while using Serilog
log.LogInformation("Logging info...");
log.LogWarning("Logging some warning!");

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

// The following exception will be captured by the SDK and the event
// will include the Log messages and any custom scope modifications
// as exemplified above.
throw new Exception("An exception thrown from the ASP.NET Core pipeline");
}
await next();
});
});

await next();
});
})
.Build();
return builder.Build();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down

This file was deleted.

This file was deleted.

43 changes: 0 additions & 43 deletions samples/Sentry.Samples.AspNetCore5.Mvc/Program.cs

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit d6dc82b

Please sign in to comment.