logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeegnesh Sheth" <jsh...@src-solutions.com>
Subject RE: Log4net in a windows service
Date Fri, 03 Oct 2008 20:36:23 GMT
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:raszka@hasam.cz] 
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:jsheth@src-solutions.com] 
	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:raszka@hasam.cz] 
	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.


Mime
View raw message