mirror of
https://github.com/bitwarden/server.git
synced 2025-04-06 05:28:15 -05:00
replace loggr with serilog
This commit is contained in:
parent
31c3835dd3
commit
49f7857d2e
@ -17,7 +17,6 @@ using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using SqlServerRepos = Bit.Core.Repositories.SqlServer;
|
||||
using System.Text;
|
||||
using Loggr.Extensions.Logging;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
@ -29,6 +28,8 @@ using IdentityServer4.Services;
|
||||
using IdentityModel.AspNetCore.OAuth2Introspection;
|
||||
using IdentityServer4.Stores;
|
||||
using Bit.Core.Utilities;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace Bit.Api
|
||||
{
|
||||
@ -198,34 +199,40 @@ namespace Bit.Api
|
||||
IApplicationBuilder app,
|
||||
IHostingEnvironment env,
|
||||
ILoggerFactory loggerFactory,
|
||||
IApplicationLifetime appLifetime,
|
||||
GlobalSettings globalSettings)
|
||||
{
|
||||
loggerFactory.AddConsole();
|
||||
loggerFactory.AddDebug();
|
||||
|
||||
if(!env.IsDevelopment())
|
||||
if(env.IsProduction())
|
||||
{
|
||||
loggerFactory.AddLoggr(
|
||||
(category, logLevel, eventId) =>
|
||||
Func<LogEvent, bool> serilogFilter = (e) =>
|
||||
{
|
||||
var context = e.Properties["SourceContext"].ToString();
|
||||
if(context == typeof(JwtBearerMiddleware).FullName && e.Level == LogEventLevel.Error)
|
||||
{
|
||||
// Bad security stamp exception
|
||||
if(category == typeof(JwtBearerMiddleware).FullName && eventId.Id == 3 && logLevel == LogLevel.Error)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// IP blocks
|
||||
if(category == typeof(IpRateLimitMiddleware).FullName && logLevel >= LogLevel.Information)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(context == typeof(IpRateLimitMiddleware).FullName && e.Level == LogEventLevel.Information)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return logLevel >= LogLevel.Error;
|
||||
},
|
||||
globalSettings.Loggr.LogKey,
|
||||
globalSettings.Loggr.ApiKey);
|
||||
return e.Level >= LogEventLevel.Error;
|
||||
};
|
||||
|
||||
var serilog = new LoggerConfiguration()
|
||||
.Enrich.FromLogContext()
|
||||
.Filter.ByIncludingOnly(serilogFilter)
|
||||
.WriteTo.AzureDocumentDB(new Uri(globalSettings.DocumentDb.Uri), globalSettings.DocumentDb.Key,
|
||||
timeToLive: TimeSpan.FromDays(7))
|
||||
.CreateLogger();
|
||||
|
||||
loggerFactory.AddSerilog(serilog);
|
||||
appLifetime.ApplicationStopped.Register(Log.CloseAndFlush);
|
||||
}
|
||||
|
||||
loggerFactory.AddDebug();
|
||||
|
||||
// Rate limiting
|
||||
app.UseMiddleware<CustomIpRateLimitMiddleware>();
|
||||
|
||||
|
@ -19,9 +19,10 @@
|
||||
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
|
||||
"Microsoft.Extensions.Configuration.Binder": "1.1.0",
|
||||
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
|
||||
"Loggr.Extensions.Logging": "1.0.0",
|
||||
"Microsoft.ApplicationInsights.AspNetCore": "1.0.2",
|
||||
"AspNetCoreRateLimit": "1.0.5"
|
||||
"AspNetCoreRateLimit": "1.0.5",
|
||||
"Serilog.Extensions.Logging": "1.3.1",
|
||||
"Serilog.Sinks.AzureDocumentDb": "3.5.17"
|
||||
},
|
||||
|
||||
"tools": {
|
||||
|
@ -29,6 +29,10 @@
|
||||
},
|
||||
"storage": {
|
||||
"connectionString": "SECRET"
|
||||
},
|
||||
"documentDb": {
|
||||
"uri": "SECRET",
|
||||
"key": "SECRET"
|
||||
}
|
||||
},
|
||||
"IpRateLimitOptions": {
|
||||
|
@ -11,6 +11,7 @@
|
||||
public virtual PushSettings Push { get; set; } = new PushSettings();
|
||||
public virtual StorageSettings Storage { get; set; } = new StorageSettings();
|
||||
public virtual IdentityServerSettings IdentityServer { get; set; } = new IdentityServerSettings();
|
||||
public virtual DocumentDbSettings DocumentDb { get; set; } = new DocumentDbSettings();
|
||||
|
||||
public class SqlServerSettings
|
||||
{
|
||||
@ -47,5 +48,11 @@
|
||||
{
|
||||
public string CertificateThumbprint { get; set; }
|
||||
}
|
||||
|
||||
public class DocumentDbSettings
|
||||
{
|
||||
public string Uri { get; set; }
|
||||
public string Key { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user