-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
5693b9b
commit d6dc82b
Showing
34 changed files
with
122 additions
and
426 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
2 changes: 1 addition & 1 deletion
2
samples/Sentry.Samples.AspNetCore.Basic/Sentry.Samples.AspNetCore.Basic.csproj
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
8 changes: 4 additions & 4 deletions
8
samples/Sentry.Samples.AspNetCore.Grpc/Sentry.Samples.AspNetCore.Grpc.csproj
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
2 changes: 1 addition & 1 deletion
2
samples/Sentry.Samples.AspNetCore.Mvc/Sentry.Samples.AspNetCore.Mvc.csproj
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,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(); | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
samples/Sentry.Samples.AspNetCore.Serilog/Sentry.Samples.AspNetCore.Serilog.csproj
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
31 changes: 0 additions & 31 deletions
31
samples/Sentry.Samples.AspNetCore5.Mvc/Controllers/HomeController.cs
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
samples/Sentry.Samples.AspNetCore5.Mvc/Models/ErrorViewModel.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
samples/Sentry.Samples.AspNetCore5.Mvc/Properties/launchSettings.json
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
samples/Sentry.Samples.AspNetCore5.Mvc/Sentry.Samples.AspNetCore5.Mvc.csproj
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.