2

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

Malcolm
  • 12,524
  • 28
  • 89
  • 125

1 Answers1

5

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
  • 25,575
  • 8
  • 51
  • 65
  • Hadi, how does this work as far as unit tests where there is no Main? Using TestDriven.Net for example – George Mauer Mar 04 '10 at 17:12
  • 1
    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 Mar 06 '10 at 09:04