feat: Add serilog sentry

This commit is contained in:
meysamhadeli 2023-01-02 21:51:53 +03:30
parent fc8f24a5e6
commit 54471a1128
10 changed files with 81 additions and 4 deletions

15
.github/workflows/release-please.yml vendored Normal file
View File

@ -0,0 +1,15 @@
# https://github.com/google-github-actions/release-please-action#how-release-please-works
# https://www.conventionalcommits.org/en/v1.0.0/
on:
push:
branches:
- main
name: release-please
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
with:
release-type: go
package-name: release-please-action

View File

@ -66,6 +66,7 @@
<PackageReference Include="OpenTelemetry.Contrib.Instrumentation.MassTransit" Version="1.0.0-beta2" />
<PackageReference Include="Scrutor" Version="4.2.0" />
<PackageReference Include="Scrutor.AspNetCore" Version="3.3.0" />
<PackageReference Include="Sentry.Serilog" Version="3.25.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageReference Include="Serilog.Enrichers.Span" Version="3.0.0" />
@ -100,6 +101,7 @@
<PackageReference Include="Duende.IdentityServer.EntityFramework.Storage" Version="6.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.1" />
<PackageReference Include="Testcontainers" Version="2.2.0" />
<PackageReference Include="Unchase.Swashbuckle.AspNetCore.Extensions" Version="2.7.1" />
<PackageReference Include="Yarp.ReverseProxy" Version="1.1.1" />
<PackageReference Include="Microsoft.Identity.Web" Version="2.0.5-preview" />

View File

@ -48,6 +48,25 @@ namespace BuildingBlocks.Logging
});
}
if (logOptions?.Sentry is {Enable: true})
{
var minimumBreadcrumbLevel = Enum.TryParse<LogEventLevel>(logOptions.Level, true, out var minBreadcrumbLevel)
? minBreadcrumbLevel
: LogEventLevel.Information;
var minimumEventLevel = Enum.TryParse<LogEventLevel>(logOptions.Sentry.MinimumEventLevel, true, out var minEventLevel)
? minEventLevel
: LogEventLevel.Error;
loggerConfiguration.WriteTo.Sentry(o =>
{
o.Dsn = logOptions.Sentry.Dsn;
o.MinimumBreadcrumbLevel = minimumBreadcrumbLevel;
o.MinimumEventLevel = minimumEventLevel;
});
}
if (logOptions.File is { Enable: true })
{
var root = env.ContentRootPath;

View File

@ -4,7 +4,9 @@
{
public string Level { get; set; }
public ElasticOptions Elastic { get; set; }
public SentryOptions Sentry { get; set; }
public FileOptions File { get; set; }
public string LogTemplate { get; set; }
}
}
}

View File

@ -0,0 +1,9 @@
namespace BuildingBlocks.Logging;
public class SentryOptions
{
public bool Enable { get; set; }
public string Dsn { get; set; }
public string MinimumBreadcrumbLevel { get; set; }
public string MinimumEventLevel { get; set; }
}

View File

@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using Unchase.Swashbuckle.AspNetCore.Extensions.Extensions;
namespace BuildingBlocks.Swagger;
@ -17,7 +18,7 @@ public static class ServiceCollectionExtensions
// https://github.com/dotnet/aspnet-api-versioning/tree/88323136a97a59fcee24517a514c1a445530c7e2/examples/AspNetCore/WebApi/MinimalOpenApiExample
public static IServiceCollection AddCustomSwagger(this IServiceCollection services,
IConfiguration configuration,
Assembly assembly)
params Assembly[] assemblies)
{
// https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/openapi
services.AddEndpointsApiExplorer();
@ -31,9 +32,14 @@ public static class ServiceCollectionExtensions
{
options.OperationFilter<SwaggerDefaultValues>();
var xmlFile = XmlCommentsFilePath(assembly);
if (File.Exists(xmlFile)) options.IncludeXmlComments(xmlFile);
foreach (var assembly in assemblies)
{
var xmlFile = XmlCommentsFilePath(assembly);
if (File.Exists(xmlFile)) options.IncludeXmlComments(xmlFile);
}
options.AddEnumsWithValuesFixFilters();
options.AddSecurityRequirement(new OpenApiSecurityRequirement
{

View File

@ -13,6 +13,12 @@
"enable": false,
"path": "logs/logs.txt",
"interval": "day"
},
"Sentry": {
"enable": false,
"dsn": "",
"minimumBreadcrumbLevel": "information",
"minimumEventLevel":"error"
}
},
"Jwt": {

View File

@ -13,6 +13,12 @@
"enable": false,
"path": "logs/logs.txt",
"interval": "day"
},
"Sentry": {
"enable": false,
"dsn": "",
"minimumBreadcrumbLevel": "information",
"minimumEventLevel":"error"
}
},
"DatabaseOptions": {

View File

@ -27,6 +27,12 @@
"enable": false,
"path": "logs/logs.txt",
"interval": "day"
},
"Sentry": {
"enable": false,
"dsn": "",
"minimumBreadcrumbLevel": "information",
"minimumEventLevel":"error"
}
},
"PersistMessageOptions": {

View File

@ -31,6 +31,12 @@
"enable": false,
"path": "logs/logs.txt",
"interval": "day"
},
"Sentry": {
"enable": false,
"dsn": "",
"minimumBreadcrumbLevel": "information",
"minimumEventLevel":"error"
}
},
"PersistMessageOptions": {