From 8a57bca1c7bef0b9754ee5c8445fc7c7dde8a528 Mon Sep 17 00:00:00 2001 From: whut Date: Sat, 4 Feb 2012 15:43:42 +0100 Subject: [PATCH] Fix for not always finding log4net, reported in https://nhibernate.jira.com/browse/NH-2821 Instead of checking for file on disk (which might fail, for example when using ShadowCopy, like when running inside NUnit), check if log4net assembly is loaded in current AppDomain. --- src/NHibernate/Logging.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/NHibernate/Logging.cs b/src/NHibernate/Logging.cs index a4c5d008295..7d52a5d4ac2 100644 --- a/src/NHibernate/Logging.cs +++ b/src/NHibernate/Logging.cs @@ -58,7 +58,7 @@ private static ILoggerFactory GetLoggerFactory(string nhibernateLoggerClass) var loggerFactoryType = System.Type.GetType(nhibernateLoggerClass); try { - loggerFactory = (ILoggerFactory) Activator.CreateInstance(loggerFactoryType); + loggerFactory = (ILoggerFactory)Activator.CreateInstance(loggerFactoryType); } catch (MissingMethodException ex) { @@ -66,7 +66,7 @@ private static ILoggerFactory GetLoggerFactory(string nhibernateLoggerClass) } catch (InvalidCastException ex) { - throw new ApplicationException(loggerFactoryType + "Type does not implement " + typeof (ILoggerFactory), ex); + throw new ApplicationException(loggerFactoryType + "Type does not implement " + typeof(ILoggerFactory), ex); } catch (Exception ex) { @@ -87,9 +87,9 @@ private static string GetNhibernateLoggerClass() string binPath = relativeSearchPath == null ? baseDir : Path.Combine(baseDir, relativeSearchPath); string log4NetDllPath = binPath == null ? "log4net.dll" : Path.Combine(binPath, "log4net.dll"); - if (File.Exists(log4NetDllPath)) + if (File.Exists(log4NetDllPath) || AppDomain.CurrentDomain.GetAssemblies().Any(a => a.GetName().Name == "log4net")) { - nhibernateLoggerClass = typeof (Log4NetLoggerFactory).AssemblyQualifiedName; + nhibernateLoggerClass = typeof(Log4NetLoggerFactory).AssemblyQualifiedName; } } else @@ -138,7 +138,7 @@ public class NoLoggingInternalLogger: IInternalLogger { public bool IsErrorEnabled { - get { return false;} + get { return false; } } public bool IsFatalEnabled