Skip to content

Commit

Permalink
Fix SonarLint warning about reducing number of conditional expressions (
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot authored and 304NotModified committed Dec 10, 2019
1 parent f7ee149 commit 7cb7213
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/NLog.Extensions.Logging/Logging/NLogLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,7 @@ private static void RegisterHiddenAssembliesForCallSite()
var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in allAssemblies)
{
if (assembly.FullName.StartsWith("NLog.Extensions.Logging,", StringComparison.OrdinalIgnoreCase)
|| assembly.FullName.StartsWith("NLog.Web,", StringComparison.OrdinalIgnoreCase)
|| assembly.FullName.StartsWith("NLog.Web.AspNetCore,", StringComparison.OrdinalIgnoreCase)
|| assembly.FullName.StartsWith("Microsoft.Extensions.Logging,", StringComparison.OrdinalIgnoreCase)
|| assembly.FullName.StartsWith("Microsoft.Extensions.Logging.Abstractions,", StringComparison.OrdinalIgnoreCase)
|| assembly.FullName.StartsWith("Microsoft.Extensions.Logging.Filter,", StringComparison.OrdinalIgnoreCase)
|| assembly.FullName.StartsWith("Microsoft.Logging,", StringComparison.OrdinalIgnoreCase))
if (ShouldAddHiddenAssembly(assembly))
{
LogManager.AddHiddenAssembly(assembly);
}
Expand All @@ -127,7 +121,31 @@ private static void RegisterHiddenAssembliesForCallSite()
#endif
}

#if NETCORE1_0
#if !NETCORE1_0
private static bool ShouldAddHiddenAssembly(Assembly assembly)
{
var assemblyFullName = assembly?.FullName;
if (string.IsNullOrEmpty(assemblyFullName))
return false;

foreach (var hiddenAssemblyPrefix in HiddenAssemblyPrefixes)
if (assemblyFullName.StartsWith(hiddenAssemblyPrefix, StringComparison.OrdinalIgnoreCase))
return true;

return false;
}

private static readonly string[] HiddenAssemblyPrefixes = new[]
{
"NLog.Extensions.Logging,",
"NLog.Web,",
"NLog.Web.AspNetCore,",
"Microsoft.Extensions.Logging,",
"Microsoft.Extensions.Logging.Abstractions,",
"Microsoft.Extensions.Logging.Filter,",
"Microsoft.Logging,"
};
#else
private static void SafeAddHiddenAssembly(string assemblyName, bool logOnException = true)
{
try
Expand All @@ -145,7 +163,7 @@ private static void SafeAddHiddenAssembly(string assemblyName, bool logOnExcepti
}
}
#endif
}
}
}


0 comments on commit 7cb7213

Please sign in to comment.