You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by jclegall <jc...@cpaglobal.com> on 2009/12/09 02:53:37 UTC
Partial logging with windows service
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.
Re: Partial logging with windows service
Posted by jclegall <jc...@cpaglobal.com>.
Awesome. Resolved!
Thanks!
Alexander-106 wrote:
>
> Try this;
>
> private void GetLogger()
> {
> if (_log != null) return;
> log4net.Config.XmlConfigurator.Configure();
> _log = LogManager.GetLogger("MyWindowsServices");
> }
>
>
> 2009/12/8 jclegall <jc...@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
>
>
--
View this message in context: http://old.nabble.com/Partial-logging-with-windows-service-tp26703955p26704816.html
Sent from the Log4net - Users mailing list archive at Nabble.com.
Re: Partial logging with windows service
Posted by Alexander <no...@gmail.com>.
Try this;
private void GetLogger()
{
if (_log != null) return;
log4net.Config.XmlConfigurator.Configure();
_log = LogManager.GetLogger("MyWindowsServices");
}
2009/12/8 jclegall <jc...@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