Radovan,

            This is how my application is set up

 

LogUtil.dll

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

 

 

Myservice.exe has the following dll's that it uses

-          Logutil.dll

-          Dosomething.dl

-          Myservice.exe.app.config

 

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

 

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

 

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

 

Placing it in myservice.exe did not produce anything

 

Thoughts/ suggestions?

 

From: Radovan Raszka [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 03, 2008 10:41 AM
To: Log4NET User
Subject: RE: Log4net in a windows service

 

there are 2 option:

1/ XmlConfigurator.Configure();

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

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

<configuration>

    <configSections>

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

    </configSections>

    <appSettings>

....

    </appSettings>

    <log4net>

....

    </log4net>

</configuration>

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 =
System.Reflection.Assembly.GetExecutingAssembly().Location;

int i = myPath.LastIndexOf('\\');

return myPath.Remove(i + 1);

}

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

 

        
________________________________


        From: Jeegnesh Sheth [mailto:[EMAIL PROTECTED] 
        Sent: Friday, October 03, 2008 4:21 PM
        To: Log4NET User
        Subject: RE: Log4net in a windows service

        Radovan,

         Can you explain:

        I prefer configure log4net using app.config file or by special
xml file, whose location can be got using service's EXE location
(Assembly.GetExecutingAssembly().Location)

         

        In my test app, which had an APP.config, when I called my
logging DLL, the right appender would get called I assumed by the
attribute

        [Assembly:
log4net.Config.XmlConfigurator(ConfigFile:="mywindowsservice.dll.config"
, Watch:=True)]

         

        If I use a special file, and I get the the Assembly executing
path, how would I pass this information down to log4net dll, so that the
right appender is called.

         

         

        From: Radovan Raszka [mailto:[EMAIL PROTECTED] 
        Sent: Friday, October 03, 2008 10:19 AM
        To: Log4NET User
        Subject: RE: Log4net in a windows service

         

        Hello,

        problem is usually caused by wrong config file location. If you
run windows service, then service's current directory is
%systemroot%\system32, not directory, where service's EXE is located on
the harddisk. Because your config file is referenced by relative path,
it can be searched in wrong location.

        I prefer configure log4net using app.config file or by special
xml file, whose location can be got using service's EXE location
(Assembly.GetExecutingAssembly().Location)

        Radovan Raszka

                 

                
________________________________


                From: Jeegnesh Sheth [mailto:[EMAIL PROTECTED] 
                Sent: Friday, October 03, 2008 3:58 PM
                To: [email protected]
                Subject: Log4net in a windows service

                Hi,

                I have a logging DLL which uses log4net to log to a
database. I have c# application which calls this logging DLL and log to
the database. Within my logging DLL I perform additional work and hence
it acts as a wrapper for log4net.

                 

                In my C# windows service project, in assemblyinfo.cs I
added 

                 

                Assembly:
log4net.Config.XmlConfigurator(ConfigFile:="mywindowsservice.dll.config"
, Watch:=True)

                 

                This config file is where I set the appeneder. If I run
my unit test it seems to work but it does not work in as a windows
service. I am using system admin privileges so it is not an issue of
previlige.

                 

                Any thoughts?

Reply via email to