views:

71

answers:

1

Hi,

So I've got a website and a console app that runs daily.

They both call a Function called ProcessIncident(). The website allows you to do it manually for an individual incident and the console app does a batch every night.

Within the function I have various log4net Log.InfoFormat() and Log.DebugFormat() calls

When I run from the website it logs fine

when I run from the console app it doesn't log at all

The path specified definatly exists

The console app config is as follows

<?xml version="1.0" encoding="utf-8" ?>
<log4net xmlns="urn:log4net">



  <logger name="NHibernate">
    <level value="OFF" />
    <appender-ref ref="NHibernateFileAppender" />
  </logger>


  <logger name="SMS">
    <level value="ALL" />
    <appender-ref ref="SmsFileAppender" />
  </logger>




<appender name="SmsFileAppender" type="log4net.Appender.RollingFileAppender">  
    <file value="D:\XXXX\SMS.IncidentBilling.log" />  
    <appendToFile value="true" />  
    <rollingStyle value="Size" />  
    <maxSizeRollBackups value="2" />  
    <maximumFileSize value="1MB" />  
    <staticLogFileName value="true" />  
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="[%date]  %-5level %logger %message %newline" />
    </layout>
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
</appender>  







  <appender name="NHibernateFileAppender" type="log4net.Appender.FileAppender">
    <file type="log4net.Util.PatternString" value="D:\Dev\SMS\Main\Source\SMS.Website\Logs\nhibernate.log" />
    <appendToFile value="true" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="[%date] %appdomain %-5level %c %message %newline" />
    </layout>
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
  </appender>








</log4net>

In the console app I have refereneced log4net dll and am declareing amember as

private  ILog Log = LogManager.GetLogger(typeof(Task));

Can anyone see anything stupid that I am doing. THere are no actual errors, just nothing is gettign logged via the console app

+1  A: 

I don't remember exactly what I did, but I think you should initialize log4net before using it.

Something like this line:

log4net.Config.XmlConfigurator.Configure();

Take a look here for more info:

Have log4net use application config file for configuration data.

See this one too (he's calling log4net.Config.BasicConfigurator.Configure();) :

Log4Net Tutorial in C# .net (How can I show log in a file?)

Leniel Macaferi
I ended up calling log4net.Config.XmlConfigurator.ConfigureAndWatch(log4netConfigFile); but you can also call it without a param adn it will look in your app.config file
Amjid Qureshi