mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 17:12:49 -05:00
update to net core 2.2
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
@ -9,17 +10,32 @@ namespace Bit.Core.Utilities
|
||||
{
|
||||
public static class LoggerFactoryExtensions
|
||||
{
|
||||
public static ILoggerFactory AddSerilog(
|
||||
this ILoggerFactory factory,
|
||||
IApplicationBuilder appBuilder,
|
||||
public static void UseSerilog(
|
||||
this IApplicationBuilder appBuilder,
|
||||
IHostingEnvironment env,
|
||||
IApplicationLifetime appLifetime,
|
||||
GlobalSettings globalSettings,
|
||||
Func<LogEvent, bool> filter = null)
|
||||
IApplicationLifetime applicationLifetime,
|
||||
GlobalSettings globalSettings)
|
||||
{
|
||||
if(env.IsDevelopment())
|
||||
{
|
||||
return factory;
|
||||
return;
|
||||
}
|
||||
|
||||
if(CoreHelpers.SettingHasValue(globalSettings?.Sentry.Dsn))
|
||||
{
|
||||
appBuilder.AddSentryContext();
|
||||
}
|
||||
applicationLifetime.ApplicationStopped.Register(Log.CloseAndFlush);
|
||||
}
|
||||
|
||||
public static ILoggingBuilder AddSerilog(
|
||||
this ILoggingBuilder builder,
|
||||
WebHostBuilderContext context,
|
||||
Func<LogEvent, bool> filter = null)
|
||||
{
|
||||
if(context.HostingEnvironment.IsDevelopment())
|
||||
{
|
||||
return builder;
|
||||
}
|
||||
|
||||
bool inclusionPredicate(LogEvent e)
|
||||
@ -36,6 +52,9 @@ namespace Bit.Core.Utilities
|
||||
return filter(e);
|
||||
}
|
||||
|
||||
var globalSettings = new GlobalSettings();
|
||||
ConfigurationBinder.Bind(context.Configuration.GetSection("GlobalSettings"), globalSettings);
|
||||
|
||||
var config = new LoggerConfiguration()
|
||||
.Enrich.FromLogContext()
|
||||
.Filter.ByIncludingOnly(inclusionPredicate);
|
||||
@ -55,8 +74,6 @@ namespace Bit.Core.Utilities
|
||||
.Enrich.WithProperty("Project", globalSettings.ProjectName)
|
||||
.Destructure.With<HttpContextDestructingPolicy>()
|
||||
.Filter.ByExcluding(e => e.Exception?.CheckIfCaptured() == true);
|
||||
|
||||
appBuilder.AddSentryContext();
|
||||
}
|
||||
else if(CoreHelpers.SettingHasValue(globalSettings.LogDirectory))
|
||||
{
|
||||
@ -66,10 +83,9 @@ namespace Bit.Core.Utilities
|
||||
}
|
||||
|
||||
var serilog = config.CreateLogger();
|
||||
factory.AddSerilog(serilog);
|
||||
appLifetime.ApplicationStopped.Register(Log.CloseAndFlush);
|
||||
builder.AddSerilog(serilog);
|
||||
|
||||
return factory;
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user