mirror of
https://github.com/bitwarden/server
synced 2026-01-03 00:53:37 +00:00
[PM-21948] Warn on deprecated logging methods (#6101)
* Add warnings and scaffold tests * Do some private reflection * Add tests for warnings * Add explainer comment * Remove Reference to Azure CosmosDb Sink * Don't warn on old file location * Update test names * Add syslog test * dotnet format * Add lazy syslog fix * Add longer wait for file * Make syslog test local only * Switch to shortened URL
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
// FIXME: Update this file to be null safe and then delete the line below
|
||||
#nullable disable
|
||||
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Bit.Core.Settings;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
@@ -33,7 +30,7 @@ public static class LoggerFactoryExtensions
|
||||
public static ILoggingBuilder AddSerilog(
|
||||
this ILoggingBuilder builder,
|
||||
WebHostBuilderContext context,
|
||||
Func<LogEvent, IGlobalSettings, bool> filter = null)
|
||||
Func<LogEvent, IGlobalSettings, bool>? filter = null)
|
||||
{
|
||||
var globalSettings = new GlobalSettings();
|
||||
ConfigurationBinder.Bind(context.Configuration.GetSection("GlobalSettings"), globalSettings);
|
||||
@@ -57,19 +54,27 @@ public static class LoggerFactoryExtensions
|
||||
return filter(e, globalSettings);
|
||||
}
|
||||
|
||||
var logSentryWarning = false;
|
||||
var logSyslogWarning = false;
|
||||
|
||||
// Path format is the only required option for file logging, we will use that as
|
||||
// the keystone for if they have configured the new location.
|
||||
var newPathFormat = context.Configuration["Logging:PathFormat"];
|
||||
|
||||
var config = new LoggerConfiguration()
|
||||
.MinimumLevel.Verbose()
|
||||
.Enrich.FromLogContext()
|
||||
.Filter.ByIncludingOnly(inclusionPredicate);
|
||||
|
||||
if (CoreHelpers.SettingHasValue(globalSettings?.Sentry.Dsn))
|
||||
if (CoreHelpers.SettingHasValue(globalSettings.Sentry.Dsn))
|
||||
{
|
||||
config.WriteTo.Sentry(globalSettings.Sentry.Dsn)
|
||||
.Enrich.FromLogContext()
|
||||
.Enrich.WithProperty("Project", globalSettings.ProjectName);
|
||||
}
|
||||
else if (CoreHelpers.SettingHasValue(globalSettings?.Syslog.Destination))
|
||||
else if (CoreHelpers.SettingHasValue(globalSettings.Syslog.Destination))
|
||||
{
|
||||
logSyslogWarning = true;
|
||||
// appending sitename to project name to allow easier identification in syslog.
|
||||
var appName = $"{globalSettings.SiteName}-{globalSettings.ProjectName}";
|
||||
if (globalSettings.Syslog.Destination.Equals("local", StringComparison.OrdinalIgnoreCase))
|
||||
@@ -107,10 +112,14 @@ public static class LoggerFactoryExtensions
|
||||
certProvider: new CertificateFileProvider(globalSettings.Syslog.CertificatePath,
|
||||
globalSettings.Syslog?.CertificatePassword ?? string.Empty));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(newPathFormat))
|
||||
{
|
||||
// Use new location
|
||||
builder.AddFile(context.Configuration.GetSection("Logging"));
|
||||
}
|
||||
else if (CoreHelpers.SettingHasValue(globalSettings.LogDirectory))
|
||||
{
|
||||
if (globalSettings.LogRollBySizeLimit.HasValue)
|
||||
@@ -138,6 +147,17 @@ public static class LoggerFactoryExtensions
|
||||
}
|
||||
|
||||
var serilog = config.CreateLogger();
|
||||
|
||||
if (logSentryWarning)
|
||||
{
|
||||
serilog.Warning("Sentry for logging has been deprecated. Read more: https://btwrdn.com/log-deprecation");
|
||||
}
|
||||
|
||||
if (logSyslogWarning)
|
||||
{
|
||||
serilog.Warning("Syslog for logging has been deprecated. Read more: https://btwrdn.com/log-deprecation");
|
||||
}
|
||||
|
||||
builder.AddSerilog(serilog);
|
||||
|
||||
return builder;
|
||||
|
||||
Reference in New Issue
Block a user