Hey I have this configuration in my web.config
In my case I forget to set the log4Net.config file properties as "Content" so the file was not included in the deploy. So pay attention on it:
Compile action : Content
Unfortunately none of the above helped. Explicit configuration in the class to be logged additionaly to the previous settings suggestions did the trick for me.
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
log4net.Config.XmlConfigurator.Configure(new FileInfo(assemblyFolder + "/log4net.config"));
I tried all of the above but nothing worked. Adding this line in app.config's configSections
section worked for me.
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" />
Ensure that Version
and PublicKeyToken
is correct
<param name="File" value="mylog.log" />
is saying "write mylog.log to actual folder". This means that if your webapp is under IIS, then log will be written to C:\inetpub\wwwroot\appname\mylog.log.
If log file is not there, then maybe account under which is app running doesn't have write permission on folder. You can run Process Monitor from SysInternals to see if and where a file is written.
Also run VS in debug mode, to see if any exceptions are thrown (Debug->Exceptions->CLR Exceptions, check Thrown).
I guess that either log4net is not logging at all, or the file is not ending up where you expect it.
Firstly, have you actually called
XmlConfigurator.Configure()
anywhere in your code? If the xml snippet above is in the application configuration file, this call will do the trick. If the xml snippet is in it's own file, you'll need to use the .Configure(string)
overload that takes the path to the file. Without this call (or apparently the assembly level attribute mentioned by Kirk Woll), then log4net won't be logging at all.
If you believe this is all done, and log4net should be logging, then maybe you should put a fully qualified path in for the log file while you debug further. That will let you be sure where the file should be.
Also after some hours, I figured out why it wasn't working for me...
i had:
public static class Program
{
private static CommunicationManager _bcScanner = new CommunicationManager();
private static ILog _log = LogManager.GetLogger(typeof(Program));
private static SocketServer socketListener;
but it should be:
public static class Program
{
private static ILog _log = LogManager.GetLogger(typeof(Program));
private static CommunicationManager _bcScanner = new CommunicationManager();
private static SocketServer socketListener;
So make sure the ILog is on the first line....