Try this; private void GetLogger() { if (_log != null) return; log4net.Config.XmlConfigurator.Configure(); _log = LogManager.GetLogger("MyWindowsServices"); }
2009/12/8 jclegall <jcleg...@cpaglobal.com>: > > I have implemented log4net for a windows service, but I get a partial > logging. > > Here is the code for my windows service: > > private ILog _log; > > protected override void OnStart(string[] args) > { > GetLogger(); > _log.Info("Starting Services"); > _log.Info("Loading configuration file"); > //Additional code here... > _log.Info("Service is running..."); > } > > protected override void OnStop() > { > GetLogger(); > _log.Info("Stopping Services"); > //Additional code here > _log.Info("Services Stopped"); > } > > private void GetLogger() > { > if (_log == null) > { > _log = LogManager.GetLogger("MyWindowsServices"); > } > } > > My adapter is: > <log4net> > <!-- Levels (from lowest to highest): ALL | DEBUG | INFO | WARN | > ERROR | FATAL | OFF | --> > <root> > <level value="ALL" /> > <appender-ref ref="RollingFileAppender" /> > </root> > > <logger name="MyWindowsServices"> > <level value="ALL"/> > </logger> > > <appender name="RollingFileAppender" > type="log4net.Appender.RollingFileAppender"> > <file value="My.Windows.Services.log" /> > <appendToFile value="true" /> > <rollingStyle value="Composite" /> > <datePattern value="yyyyMMdd" /> > <maxSizeRollBackups value="10" /> > <maximumFileSize value="3MB" /> > <staticLogFileName value="true" /> > <immediateFlush value="true" /> > <layout type="log4net.Layout.PatternLayout"> > <header value="[Session Start] "/> > <footer value="[Session End] "/> > <conversionPattern value="%date [%thread] %-5level %logger > [%property{NDC}] - %message%newline" /> > </layout> > </appender> > </log4net> > > The result of my log file contains only the log information from the Start > method of the windows service, but nothing for the stop: > [Session Start] > 2009-12-09 10:39:13,986 [4] INFO MyWindowsServices [(null)] - Starting > Services > 2009-12-09 10:39:14,018 [4] INFO MyWindowsServices [(null)] - Loading > configuration file > 2009-12-09 10:39:14,033 [4] INFO MyWindowsServices [(null)] - Service is > running... > [Session End] > > What's wrong? > > Thanks for your help! > > -- > View this message in context: > http://old.nabble.com/Partial-logging-with-windows-service-tp26703955p26703955.html > Sent from the Log4net - Users mailing list archive at Nabble.com. > > -- Sincerely, Alexander N. Ogden Nash - "The trouble with a kitten is that when it grows up, it's always a cat." - http://www.brainyquote.com/quotes/authors/o/ogden_nash.html