How to use log4net for a windows forms application using COM classes

C

chidam.chidam

Hi all,
I would like to implement log4net for logging my application. First
let me describe in short about the application. I have a solution with
two exe file outputs and several dll assemblies. And my application has
a different AppDomain as it is a customization of another COM based
application written in VB.NET.

I have tried with App.Config files in my startup exe applications. It
works fine only till the parent application is loaded after that even
though the customized assemblies are used. My logging is not happening.


I am using the following set of code in every class.

1) log4net.Config.DOMConfigurator.Configure(); in every class'
constructor
2) Private Shared ReadOnly log as ILog =
LogManager.GetLogger(GetTypeof(FastLogger));

My installation folder has the following files apart from other
assemblies:

1) MyApp.Exe
2) MyApp.Exe.Config
3) But it starts another application ForeignApp.exe in some other
folder.

Can anyone please help me in this regard.

Thanks in anticipation,
Chidam
 
A

Andrew Backer

You have a more complicated setup than I have dealt with in .net, but
in java it was easy enough. I sure hope it's that way here.

I have a "log4net.config" file in my app directory
I do *not* initialize log4net anywhere
In my assemblyinfo is this line which causes log4net to reload itself
if the config changes:
<Assembly: log4net.Config.XmlConfigurator(ConfigFile:="log4net.config",
ConfigFileExtension:="config", Watch:=True)>

At the top of each class is this generic code :
Private Shared ReadOnly log As ILog =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)

This gets a logger based on the class being instantiated. In other
versions with the plain text config file you could always just
reference your class/namespace like this :
"log4j.logger.com.myapp.data=dataquerylog,emailerrorlog" and it would
use those loggers for all classes in that namespace that loaded a
logger that was not explicitly named (ie, FastLogger). I assume there
is a way to do this in the xml config file (or maybe it supports a text
config too?) and maybe that is what you are looking for.

Hope this helps. If a second exe is run in the same working directory
I think it would load up the same log4net.config (xml format) when run.


HTH, and sorry I can't be much more help than that.

// Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top