tags:

views:

762

answers:

2

Hi,

I have enabled log4net and run my app which is giving an exception.

But the log file is empty.

Doesn't NHibernate log info about the exception???

Malcolm

A: 

Hi!

Could you please provide more details:

What exception is being thrown? How did you enable log4net? Do you see other log entries from nhibernate?

Nikolay R
+3  A: 

You need to configure log4net. Just by adding log4net dll to the project doesn't log anything. You need to create appenders to specify where all the loggin should be directed to. Create a xml file like this one:


<log4net>  
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">  
        <file value="Logs\Trace.log" />  
        <appendToFile value="true" />  
        <rollingStyle value="Composite" />  
        <maxSizeRollBackups value="30" />  
        <maximumFileSize value="1000KB" />  
        <layout type="log4net.Layout.PatternLayout">  
            <conversionPattern value="%date [%thread] %-5level - %message%newline" />  
        </layout>  
        <threshold value="DEBUG"/>  
    </appender>  
    <root>  
        <appender-ref ref="RollingFileAppender" />  
    </root>  
</log4net>  

...and configure it when starting up the application:


   public static void Main()
   {  
      var logconfig = new System.IO.FileInfo(PATH_TO_LOG_CONFIG);  
      if(logconfig.Exists)  
      {  
          log4net.Config.XmlConfigurator.ConfigureAndWatch(logconfig);  
      }  
   }  

Hadi Eskandari
Hadi, how does this work as far as unit tests where there is no Main? Using TestDriven.Net for example
George Mauer
Why not configure Log4Net in your test setup (i.e base class) to create a ConsoleAppender and redirect all log messages to Console? Most test runners display them in one way or the other.
Hadi Eskandari