Can I have multiple log4net configuration files? - log4net

Can I have multiple log4net configurations for the same program? Functionality similar to Spring's <import> element would be optimal. The idea here would to have multiple programs that have their own log4net configuration, as well as sharing a central log4net configuration file containing a shared error log (so that definition isn't repeated). Alternatively is this functionality possible with .NET Common Logging?
Related: log4net - configure using multiple configuration files

you can achieve this by using named repositories i think
log4net.LogManager.CreateRepository(repositoryName)
log4net.Config.XmlConfigurator.Configure(repositoryName, configFile)
then by using
LogManager.GetLogger(repositoryName,loggerName)
you can get the corresponding logger.

Not out-of-the-box. You must implement yourself the merging of different config files into a single XmlNode and pass this to log4net XmlConfiguratot.
An example is to be found here: http://www.kopf.com.br/kaplof/using-multiple-configuration-files-with-log4net

Related

Load Log4net custom appender from a library outside the application folder

I have a C# custom appender library which needs to be used by several applications in different solutions which run in the same server. I have an addon installer solution that creates all the folders and stuffs which includes the custom appender library, which the other projects needs to use. Instead of adding this library into all the application's directory, I just want to let the each application's App.Config to point to this single custom appender library.
I have built a custom appender call MyCustomAppender in a library call MyCustomLibrary.dll.
Here is the xml code of one of the App.Configs:
<appender name="MyCustomAppender" type="MyCustomerLibrary.MyCustomAppender, C:\Users\Admin\Libraries\MyCustomLibrary">
It is not possible for me to put the path of the library because Log4net doesn't work this way. Is there a walk around for each application to point to C:\Users\Admin\Libraries\MyCustomLibrary.dll? to use the MyCustomAppender? The other applications needs to have 0 code changes, only their App.Config can be modified due the the reason this process needs to have minimal changes.
You can add the dll to the GAC on the machine your application is runnen. This will allow all programs to find the dll. BTW, coping the dll into the bin directory of the application will not change the code of the application.

Multiple Configuration Files with Log4Net

I would like to have a company wide log4net configuration file but allow individuals to add additional appenders to their on application. How can I setup Log4Net to incorporate all appenders (from the system wide and the application specific).
I have considered reading in both xml documents and dynamically writing out a combined one but this seems error-prone.
Ideas??
The solution is to build a class that merges all the log4net sections in an in-memory XmlDocument and pass this to log4net.
The implementation of this class and its usage can be found on:
http://www.kopf.com.br/kaplof/using-multiple-configuration-files-with-log4net

Multiple log files using Log4j

I have a web application, that is build on spring webflow and jsf. Multiple users can log into my application at the same time. Now I want to use log4j to, of course, do the logging.
My question: is it possible to let log4j create different log files for every connected user?
thanks, Nikolaus
No, statically configured log4j cannot do it (unless your user set is constant and known upfront), you'd have to implement something on top of it that would set the configuration programatically.
If logback can do it, as fge says, use it, best not directly, but through slf4j.

Using log4net in a complex software

I'm using log4net logging in my software that consists of several applications.
I want to have one common library for this.
I created a library and put it in the conficuration file. In AssemblyInfo.cs placed attribute:
log4net.Config.XmlConfigurator(ConfigFile = #"c:\logging.xml", Watch = true)
It work for windows service, but in dosn't work for asp.net application.
It work in asp.net if delete attribute from common library and put in into global.asax. However, this leads to that section of the log4net configuration must be made in the windows service.
There is also a business process which causes our library through the
remouting. I want the logging was carried out there too.
Is there way around this?
In my opinion the library should not define where the configuration file is found. Maybe a better idea would be to have a helper method that allows you to configure log4net quickly; that method would take an optional parameter for the config file path and would try to load the configuration file from the specified path first and if that does not work fallback to some maybe the current folder, the application folder or even the web / app.config.
If you insist that it must be an absolute path then you need to give the IIS Application Pool user read access to this file. This way the configuration by attribute should work for services and ASP.Net applications. I do not understand what you mean by "remounting".

Linqpad and Log4net

I have linqpad referencing one of my own assemblies which uses log4net. When linqpad calls my assembly method I am setting my log4net logging levels to ERROR yet I see debug level messages from my assembly showing up in the linqpad results area.
Anybody know what causes this? Does Linqpad use log4net itself or have any special behavior with log4net?
LINQPad uses SharpDevelop which has a dependency on log4net, but this is kept pretty well isolated to the UI domain and shouldn't have any effect on your queries.
How are you configuring log4net? Is it programmatically or via an application config file? If it's the latter, the application config file should be named linqpad.config in order to be picked up by your queries.
I was having trouble with my configuration not being picked up. Creating a separate Linqpad.config (not editing LINQPad's own!) is the key bit of info I was missing - thanks Joe. Fantastic app by the way!

Resources