Skip to content

Commit

Permalink
AppDomainWrapper - Unhandled exception on Linux without ICU package (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot authored Apr 9, 2023
1 parent a649266 commit b171b45
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/NLog/Internal/AppDomains/AppDomainWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ public AppDomainWrapper(AppDomain appDomain)
BaseDirectory = string.Empty;
}

try
{
FriendlyName = appDomain.FriendlyName;
}
catch (Exception ex)
{
InternalLogger.Warn(ex, "AppDomain.FriendlyName Failed");
FriendlyName = GetFriendlyNameFromEntryAssembly() ?? GetFriendlyNameFromProcessName() ?? string.Empty;
}

try
{
ConfigurationFile = LookupConfigurationFile(appDomain);
Expand All @@ -85,7 +95,6 @@ public AppDomainWrapper(AppDomain appDomain)
PrivateBinPath = ArrayHelper.Empty<string>();
}

FriendlyName = appDomain.FriendlyName;
Id = appDomain.Id;
}

Expand Down Expand Up @@ -115,6 +124,32 @@ private static string[] LookupPrivateBinPath(AppDomain appDomain)
#endif
}

private static string GetFriendlyNameFromEntryAssembly()
{
try
{
string assemblyName = Assembly.GetEntryAssembly()?.GetName()?.Name;
return string.IsNullOrEmpty(assemblyName) ? null : assemblyName;
}
catch
{
return null;
}
}

private static string GetFriendlyNameFromProcessName()
{
try
{
string processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
return string.IsNullOrEmpty(processName) ? null : processName;
}
catch
{
return null;
}
}

/// <summary>
/// Creates an AppDomainWrapper for the current <see cref="AppDomain"/>
/// </summary>
Expand Down

0 comments on commit b171b45

Please sign in to comment.