1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-04 01:22:50 -05:00

Add sentry logging support. (#240)

This commit is contained in:
David Roth
2018-03-23 18:33:31 +01:00
committed by Kyle Spearrin
parent bf3c01ac46
commit 702d833cea
15 changed files with 44 additions and 7 deletions

View File

@ -72,6 +72,7 @@
<PackageReference Include="IdentityServer4" Version="2.1.2" />
<PackageReference Include="Dapper" Version="1.50.4" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
<PackageReference Include="Serilog.Sinks.Sentry.AspNetCore" Version="2.1.4" />
<PackageReference Include="WindowsAzure.Storage" Version="9.0.0" />
<PackageReference Include="AspNetCoreRateLimit" Version="2.1.0" />
<PackageReference Include="Braintree" Version="3.12.0" />

View File

@ -22,6 +22,7 @@ namespace Bit.Core
public virtual IdentityServerSettings IdentityServer { get; set; } = new IdentityServerSettings();
public virtual DataProtectionSettings DataProtection { get; set; } = new DataProtectionSettings();
public virtual DocumentDbSettings DocumentDb { get; set; } = new DocumentDbSettings();
public virtual SentrySettings Sentry { get; set; } = new SentrySettings();
public virtual NotificationHubSettings NotificationHub { get; set; } = new NotificationHubSettings();
public virtual YubicoSettings Yubico { get; set; } = new YubicoSettings();
public virtual DuoSettings Duo { get; set; } = new DuoSettings();
@ -115,6 +116,11 @@ namespace Bit.Core
public string Key { get; set; }
}
public class SentrySettings
{
public string Dsn { get; set; }
}
public class NotificationHubSettings
{
private string _connectionString;

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
@ -10,6 +11,7 @@ namespace Bit.Core.Utilities
{
public static ILoggerFactory AddSerilog(
this ILoggerFactory factory,
IApplicationBuilder appBuilder,
IHostingEnvironment env,
IApplicationLifetime appLifetime,
GlobalSettings globalSettings,
@ -32,6 +34,16 @@ namespace Bit.Core.Utilities
config.WriteTo.AzureDocumentDB(new Uri(globalSettings.DocumentDb.Uri), globalSettings.DocumentDb.Key,
timeToLive: TimeSpan.FromDays(7));
}
else if(globalSettings.Sentry != null && CoreHelpers.SettingHasValue(globalSettings.Sentry.Dsn))
{
config.WriteTo.Sentry(globalSettings.Sentry.Dsn)
.Enrich.FromLogContext()
.Enrich.WithProperty("Project", globalSettings.ProjectName)
.Destructure.With<HttpContextDestructingPolicy>()
.Filter.ByExcluding(e => e.Exception?.CheckIfCaptured() == true);
appBuilder.AddSentryContext();
}
else if(CoreHelpers.SettingHasValue(globalSettings.LogDirectory))
{
config.WriteTo.RollingFile($"{globalSettings.LogDirectory}/{globalSettings.ProjectName}/{{Date}}.txt");