Linqpad and Log4net - 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!

Related

moving from log4cxx to log4net

I have a largish application that currently uses log4cxx as its logging system. However, these appears to be a dead project, and I cannot get it to work with Visual Studio 2013. As such, I am looking to move to log4net
Our project is a mixed C+/C# project, using .net 3.5, and the logging is pretty simple
What is the best way to handle this migration. Any particular problems that people would expect to see, any required changes to config files, etc.
Also, is there a simple tutorial on how to use log4net. Unless I'm misreading it, it appears to be a case of reading the source examples until you figure it out.

Log4Net not working for console app

I have a console app and I am trying to implement log4Net for it.
I did the following steps -
added log4Net reference
Created Log4Net.config -
Created the LogHelper.cs class -
Added the following to the AssemblyInfo.cs
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4net.config", Watch = true)]
But the logging doesnt seem to work? Can someone suggest what needs to be done for the logging to work in th console app?
Make sure the config file is set to copy to the output directory.
In the log4net documentation for assembly attributes it says:
".. if you use configuration attributes you must invoke log4net to
allow it to read the attributes. A simple call to LogManager.GetLogger
will cause the attributes on the calling assembly to be read and
processed. Therefore it is imperative to make a logging call as
early as possible during the application start-up, and certainly
before any external assemblies have been loaded and invoked."
If it still doesn't work, enable log4net debugging as in this answer

Umbraco DotNetOpenAuth log4net

In an Umbraco v6.1.6 I'm trying to get log messages from DotNetOpenAuth. Umbraco already comes with log4net, version 1.2.11.0 without a public key token. The Umbraco logs work fine, but I see no messages from DotNetOpenAuth. I also tried to add a second log4net.dll assembly, the one signed with the public key 669e0ddf0bb1aa2a, while also keeping the non signed one, but to no avail. Any ideas what could go wrong?
I have exactly the same setup and tried all manner of web.config redirects and log4net versions to no avail. The problem is Umbraco is built with an unsigned version of log4net. You have a few options here:
Try to get dotnetopenauth to use trace logging. It will default to this when it can't load log4net. I had problems determining if the trace logging was actually working or not.
Build your own version of dotnetopenauth - at least you'll be able to debug. Follow these instructions

Can I have multiple log4net configuration files?

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

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".

Resources