Skip to content

Commit 0ba2443

Browse files
authored
Improve loading of nlog-config with .NET6 single file publish (#4820)
1 parent c42acda commit 0ba2443

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/NLog/Internal/Fakeables/AppEnvironmentWrapper.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,19 @@ private static string LookupEntryAssemblyFileName()
9999
{
100100
try
101101
{
102-
return Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly()?.Location ?? string.Empty);
102+
var entryAssembly = System.Reflection.Assembly.GetEntryAssembly();
103+
var assemblyLocation = entryAssembly?.Location;
104+
if (!string.IsNullOrEmpty(assemblyLocation))
105+
{
106+
return Path.GetFileName(assemblyLocation);
107+
}
108+
109+
// Fallback to the Assembly-Name when unable to extract FileName from Location
110+
var assemblyName = entryAssembly?.GetName()?.Name;
111+
if (!string.IsNullOrEmpty(assemblyName))
112+
return assemblyName + ".dll";
113+
else
114+
return string.Empty;
103115
}
104116
catch (Exception ex)
105117
{

0 commit comments

Comments
 (0)