Radovan,

LogUtil.dll

This has some custom logging as well as log4net dll reference and uses a custom 
appender to log. This is where I perform

 

 

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

-          Dosomething.dl -à uses Logutil.dll and is included as a reference.

-          Myservice.exe.app.config

 

 

>From your information, I assume I should do this in LogUtil.dll and in the 
>default cstor of Logutil, I should obtain the path to the 
>myservice.exe.app.config path and set it.

        log = LogManager.GetLogger(typeof(LogUtil)); in the cstor

 

Myservice.exe does not need to do any logging, only DoSomething library needs 
to perform the logging.

 

 

The error I get is a generic  .Net framework error showing all the assemblies 
which caused the error which may be due to versioning but the logs do not 
indicate this. So I did a clean install and that error was no longer the case 
but then it came down to just a system violation error each time I try to 
perform xmlconfigurator.configure() in the default cstor of the Myservice.

 

Thanks

 

 

From: Radovan Raszka [mailto:[EMAIL PROTECTED] 
Sent: Saturday, October 04, 2008 4:32 PM
To: Log4NET User
Subject: RE: Log4net in a windows service

 

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 = false;

        this.CanShutdown = true;

        this.CanHandleSessionChangeEvent = false;

        this.AutoLog = false;

        this.ServiceName = IPservice.SrvName;

        XmlConfigurator.Configure();

        log = LogManager.GetLogger(typeof(IPservice));

    }

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

    protected override void OnStop() {...}

}

         

        
________________________________


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

        Radovan,

         Myservice.exe has the following:

        Default cstor

         

        A main entry point into process, named main

         

         

        Onstart and onstop methods

         

        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.

         

         

        Many thanks

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

         

        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 <projectname>.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 <processname>.exe.config), so save config into 
Myservice.exe.config or use second example.

        Radovan

                 

                
________________________________


                From: Jeegnesh Sheth [mailto:[EMAIL PROTECTED] 
                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

                 

                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.

Reply via email to