Skip to content

Commit

Permalink
Prevent GetLogger from being called before NLog init
Browse files Browse the repository at this point in the history
  • Loading branch information
bording committed Mar 18, 2024
1 parent ddf3eae commit aa7fdb2
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 11 deletions.
Expand Up @@ -289,7 +289,7 @@ int GetDataSpaceRemainingThreshold()

void TryLoadLicenseFromConfig() => LicenseFileText = SettingsReader.Read<string>(SettingsRootNamespace, "LicenseText");

ILog logger = LogManager.GetLogger(typeof(Settings));
readonly ILog logger = LogManager.GetLogger(typeof(Settings));
int maxBodySizeToStore = SettingsReader.Read(SettingsRootNamespace, "MaxBodySizeToStore", MaxBodySizeToStoreDefault);
public const string DEFAULT_SERVICE_NAME = "Particular.ServiceControl.Audit";
public static readonly SettingsRootNamespace SettingsRootNamespace = new("ServiceControl.Audit");
Expand Down
4 changes: 1 addition & 3 deletions src/ServiceControl.Audit/Program.cs
Expand Up @@ -22,7 +22,7 @@ class Program
static async Task Main(string[] args)
{
AssemblyLoadContext.Default.Resolving += ResolveAssembly;
AppDomain.CurrentDomain.UnhandledException += (s, e) => Logger.Error("Unhandled exception was caught.", e.ExceptionObject as Exception);
AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception);

ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly());

Expand Down Expand Up @@ -75,7 +75,5 @@ static Assembly TryLoadAssembly(AssemblyLoadContext loadContext, string folderPa

return null;
}

static readonly ILog Logger = LogManager.GetLogger(typeof(Program));
}
}
4 changes: 1 addition & 3 deletions src/ServiceControl.Monitoring/Program.cs
Expand Up @@ -17,7 +17,7 @@ static class Program
static async Task Main(string[] args)
{
AssemblyLoadContext.Default.Resolving += ResolveAssembly;
AppDomain.CurrentDomain.UnhandledException += (s, e) => Logger.Error("Unhandled exception was caught.", e.ExceptionObject as Exception);
AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception);

ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly());

Expand Down Expand Up @@ -65,7 +65,5 @@ static Assembly TryLoadAssembly(AssemblyLoadContext loadContext, string folderPa

return null;
}

static readonly ILog Logger = LogManager.GetLogger(typeof(Program));
}
}
2 changes: 1 addition & 1 deletion src/ServiceControl/Infrastructure/Settings/Settings.cs
Expand Up @@ -421,7 +421,7 @@ void LoadErrorIngestionSettings()

void TryLoadLicenseFromConfig() => LicenseFileText = SettingsReader.Read<string>(SettingsRootNamespace, "LicenseText");

static readonly ILog logger = LogManager.GetLogger(typeof(Settings));
readonly ILog logger = LogManager.GetLogger(typeof(Settings));
public const string DEFAULT_SERVICE_NAME = "Particular.ServiceControl";
public static readonly SettingsRootNamespace SettingsRootNamespace = new("ServiceControl");

Expand Down
4 changes: 1 addition & 3 deletions src/ServiceControl/Program.cs
Expand Up @@ -21,7 +21,7 @@ class Program
static async Task Main(string[] args)
{
AssemblyLoadContext.Default.Resolving += ResolveAssembly;
AppDomain.CurrentDomain.UnhandledException += (s, e) => Logger.Error("Unhandled exception was caught.", e.ExceptionObject as Exception);
AppDomain.CurrentDomain.UnhandledException += (s, e) => LogManager.GetLogger(typeof(Program)).Error("Unhandled exception was caught.", e.ExceptionObject as Exception);

ExeConfiguration.PopulateAppSettings(Assembly.GetExecutingAssembly());

Expand Down Expand Up @@ -74,7 +74,5 @@ static Assembly TryLoadAssembly(AssemblyLoadContext loadContext, string folderPa

return null;
}

static readonly ILog Logger = LogManager.GetLogger(typeof(Program));
}
}

0 comments on commit aa7fdb2

Please sign in to comment.