Return-Path: Delivered-To: apmail-logging-log4net-user-archive@www.apache.org Received: (qmail 48512 invoked from network); 4 Oct 2008 20:30:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Oct 2008 20:30:18 -0000 Received: (qmail 49151 invoked by uid 500); 4 Oct 2008 20:30:16 -0000 Delivered-To: apmail-logging-log4net-user-archive@logging.apache.org Received: (qmail 49119 invoked by uid 500); 4 Oct 2008 20:30:16 -0000 Mailing-List: contact log4net-user-help@logging.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Log4NET User" List-Id: Delivered-To: mailing list log4net-user@logging.apache.org Received: (qmail 49108 invoked by uid 99); 4 Oct 2008 20:30:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Oct 2008 13:30:16 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [217.112.162.197] (HELO main.hasam.cz) (217.112.162.197) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Oct 2008 20:29:15 +0000 Subject: RE: Log4net in a windows service Date: Sat, 4 Oct 2008 22:31:32 +0200 Message-ID: <0794C17B67A72245B24284103E4959D2385C@main.hasam.cz> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C92660.30403540" In-Reply-To: <68A39D9C74BD8241B3659184041D6F633C89E3@SRCEXC.srchq.src-solutions.com> X-MS-Has-Attach: Content-class: urn:content-classes:message X-MS-TNEF-Correlator: X-MimeOLE: Produced By Microsoft Exchange V6.5 thread-topic: Log4net in a windows service thread-index: AcklYAGlRXdVJu3mSzKccwns9Bc1WAAAiM4gAAAz88AAAHelsAAJ+TBQAAD+pSAAAaX2oAAyBKog References: <68A39D9C74BD8241B3659184041D6F633A820F@SRCEXC.srchq.src-solutions.com> <0794C17B67A72245B24284103E4959D23859@main.hasam.cz> <68A39D9C74BD8241B3659184041D6F633A8212@SRCEXC.srchq.src-solutions.com> <0794C17B67A72245B24284103E4959D2385A@main.hasam.cz> <68A39D9C74BD8241B3659184041D6F633C89CF@SRCEXC.srchq.src-solutions.com> <0794C17B67A72245B24284103E4959D2385B@main.hasam.cz> <68A39D9C74BD8241B3659184041D6F633C89E3@SRCEXC.srchq.src-solutions.com> From: "Radovan Raszka" To: "Log4NET User" X-Virus-Checked: Checked by ClamAV on apache.org This is a multi-part message in MIME format. ------_=_NextPart_001_01C92660.30403540 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I configure log4net in main service class constructor. What kind of crash have you met - any exception (what?) ? public class IPservice : ServiceBase { ... public IPservice() { InitializeComponent(); this.CanPauseAndContinue =3D false; this.CanShutdown =3D true; this.CanHandleSessionChangeEvent =3D false; this.AutoLog =3D false; this.ServiceName =3D IPservice.SrvName; XmlConfigurator.Configure(); log =3D LogManager.GetLogger(typeof(IPservice)); } protected override void OnStart(string[] args){ ...} protected override void OnStop() {...} } ________________________________ From: Jeegnesh Sheth [mailto:jsheth@src-solutions.com]=20 Sent: Friday, October 03, 2008 10:36 PM To: Log4NET User Subject: RE: Log4net in a windows service =09 =09 Radovan, Myservice.exe has the following: Default cstor =20 A main entry point into process, named main =20 =20 Onstart and onstop methods =20 If I place the XMlConfiguartor.configure() in any of the methods above, my applications keeps crashing. Is there something I am missing? I am trying to use your first solution. =20 =20 Many thanks From: Radovan Raszka [mailto:raszka@hasam.cz]=20 Sent: Friday, October 03, 2008 3:58 PM To: Log4NET User Subject: RE: Log4net in a windows service =20 Ok, there is also dependency on where log4net is set up. Examples in my last mail works, if log4net is configured from Myservice.exe (not from DLL), and config is stored in Myservice.exe.config (you add app.config to the project, but Visual studio copies this file to the output folder as .exe.config, what is correct) If configuration is done from DLL, then logutil.DLL.config probably can not be used (at least it didn't work for me and I was told that application file is always searched as .exe.config), so save config into Myservice.exe.config or use second example. Radovan =20 =09 ________________________________ From: Jeegnesh Sheth [mailto:jsheth@src-solutions.com]=20 Sent: Friday, October 03, 2008 9:22 PM To: Log4NET User Subject: RE: Log4net in a windows service Radovan, This is how my application is set up =20 LogUtil.dll This has some custom logging as well as log4net dll reference and uses a custom appender to log =20 =20 Myservice.exe has the following dll's that it uses - Logutil.dll - Dosomething.dl - Myservice.exe.app.config =20 Dosomthing.dll instantiates logutil.dll to write the logs. =20 I tried putting your xmlconfigurator.configure in logutil.dll and that did not work =20 I then tried placing it in dosomething.dll which did not work =20 Placing it in myservice.exe did not produce anything =20 Thoughts/ suggestions? =20 From: Radovan Raszka [mailto:raszka@hasam.cz]=20 Sent: Friday, October 03, 2008 10:41 AM To: Log4NET User Subject: RE: Log4net in a windows service =20 there are 2 option: 1/ XmlConfigurator.Configure(); this configures log4net using app.config file, which must be in this form:
.... .... This is probably best solution as you have only one config file for both application and log4net. 2/ configure log4net using extra XML file XmlConfigurator.Configure(new System.IO.FileInfo(GetAppPath() + "log4net.xml")) ..... public string GetAppPath() { string myPath =3D System.Reflection.Assembly.GetExecutingAssembly().Location; int i =3D myPath.LastIndexOf('\\'); return myPath.Remove(i + 1); } Both solutions works well with service, but when log4net config is changed, you must restart your service. ------_=_NextPart_001_01C92660.30403540 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
I configure log4net in main service class = constructor. What=20 kind of crash have you met - any exception (what?) = ?

public class IPservice :=20 ServiceBase

{ ...

    public=20 IPservice()

   =20 {

       =20 InitializeComponent();

       =20 this.CanPauseAndContinue =3D false;

       =20 this.CanShutdown =3D true;

       =20 this.CanHandleSessionChangeEvent =3D false;

       =20 this.AutoLog =3D false;

       =20 this.ServiceName =3D IPservice.SrvName;

       =20 XmlConfigurator.Configure();

        = log =3D=20 LogManager.GetLogger(typeof(IPservice));

   =20 }

    protected = override void OnStart(string[] args){ ...}

    protected = override void OnStop() {...}

}



From: Jeegnesh Sheth=20 [mailto:jsheth@src-solutions.com]
Sent: Friday, October 03, = 2008=20 10:36 PM
To: Log4NET User
Subject: RE: Log4net in = a=20 windows service

Radovan,

 Myservice.exe=20 has the following:

Default=20 cstor

 

A=20 main entry point into process, named main

 

 

Onstart=20 and onstop methods

 

If I=20 place the XMlConfiguartor.configure() in any of the methods above, my=20 applications keeps crashing. Is there something I am missing? I am = trying to=20 use your first solution.

 

 

Many=20 thanks

From: Radovan = Raszka=20 [mailto:raszka@hasam.cz]
Sent: Friday, October 03, 2008 = 3:58=20 PM
To: Log4NET User
Subject: RE: Log4net in a = windows=20 service

 

Ok,=20 there is also dependency on where log4net is set up.

Examples=20 in my last mail works, if log4net is configured from Myservice.exe = (not from=20 DLL), and config is stored in Myservice.exe.config (you add app.config = to the=20 project, but Visual studio copies this file to the output folder as=20 <projectname>.exe.config, what is correct)

If=20 configuration is done from DLL, then logutil.DLL.config probably can = not be=20 used (at least it didn't work for me and I was told that application = file is=20 always searched as <processname>.exe.config), so save config = into=20 Myservice.exe.config or use second example.

Radovan

 


From:=20 Jeegnesh Sheth [mailto:jsheth@src-solutions.com]
Sent: = Friday,=20 October 03, 2008 9:22 PM
To: Log4NET = User
Subject: RE:=20 Log4net in a windows service

Radovan,

         = ;  =20 This is how my application is set up

 

LogUtil.dll

This=20 has some custom logging as well as log4net dll reference and uses a = custom=20 appender to log

 

 

Myservice.exe=20 has the following dll’s that it uses

-         =20 Logutil.dll

-         =20 Dosomething.dl

-         =20 Myservice.exe.app.config

 

Dosomthing.dll=20 instantiates logutil.dll to write the logs.

 

I=20 tried putting your xmlconfigurator.configure in logutil.dll and that = did not=20 work

 

I=20 then tried placing it in dosomething.dll which did not=20 work

 

Placing=20 it in myservice.exe did not produce anything

 

Thoughts/=20 suggestions?

 

From: = Radovan Raszka=20 [mailto:raszka@hasam.cz]
Sent: Friday, October 03, 2008 = 10:41=20 AM
To: Log4NET User
Subject: RE: Log4net in a = windows=20 service

 

there=20 are 2 option:

1/=20 XmlConfigurator.Configure();

this = configures=20 log4net using app.config file, which must be in this = form:

<?xml version=3D"1.0" encoding=3D"utf-8" ?>

<configuration>

   =20 <configSections>

       =20 <section name=3D"log4net" type=3D"log4net.Config.Log4NetConfigurationSectionHandler,=20 log4net" = />

   =20 </configSections>

   =20 <appSettings>

....

   =20 </appSettings>

   =20 <log4net>

....

   =20 </log4net>

</configuration>

This=20 is probably best solution as you have only one config file for both=20 application and log4net.

2/=20 configure log4net using extra XML file

XmlConfigurator.Configure(new=20 System.IO.FileInfo(GetAppPath() + = "log4net.xml"))

.....

public string=20 GetAppPath()

{

string=20 myPath =3D System.Reflection.Assembly.GetExecutingAssembly().Location;=

int=20 i =3D myPath.LastIndexOf('\\');

return=20 myPath.Remove(i + 1);

}

Both=20 solutions works well with service, but when log4net config is = changed, you=20 must restart your=20 service.

------_=_NextPart_001_01C92660.30403540--