NHibernate enable log4net

I turned on log4net and ran my application which gives an exception.

But the log file is empty.

Does NHibernate not log exception information ???

Malcolm

+2
source share
1 answer

You need to configure log4net. Just adding log4net dll to the project doesn't write anything. You need to create an application to indicate where all logging should go. Create an xml file like this:


<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 the application starts:


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

+5
source

Source: https://habr.com/ru/post/1721718/


All Articles