Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4net unable to write, only creating empty files, but not writing actual logs

i am unable to write log any info, error, debug using log4net, i tried everything gave permsission to network service, everyone to directories asp.net temp folder, log folder, even c:\,

it just create a empty file. but do not write log

what could be the issue

Thx Raj

like image 262
Techmaster Avatar asked Jun 20 '11 16:06

Techmaster


People also ask

Where are log4net logs stored?

You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation. The different log files are described in Services logs.

What are log4net Appenders?

For log4net to know where to store your log messages, you add one or more appenders to your configuration. An appender is a C# class that can transform a log message, including its properties, and persist it somewhere. Examples of appenders are the console, a file, a database, an API call, elmah.io, etc.

What is the use of log4net DLL?

The Apache log4net library is a tool to help the programmer output log statements to a variety of output targets. log4net is a port of the excellent Apache log4j™ framework to the Microsoft® . NET runtime.


2 Answers

My guess would be that in your config file, you didn't specify a layout pattern. Normally, you have something that looks like this inside your appender:

<layout type="log4net.Layout.PatternLayout">
  <conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>

That specifies what to write to the log. If you don't have that, I doubt it will write anything.

I agree with those in the comments who said this probably isn't a permissions issue because the file gets created. To test that this is true, you could add an appender to your config that outputs to the console. Then you could watch the output as you debug your application. If that doesn't work either, you know the issue isn't a permissions issue.

The best suggestion I can give would be to compare your config file with a working one. Make sure that every section has a counterpart in the working config or that you know why it doesn't need to have one. Here is an article I wrote on log4net that includes explanations on every section of the config and it shows how to write them:

http://www.codeproject.com/KB/dotnet/Log4net_Tutorial.aspx

If all of this doesn't help, please post your config file text in your question so we can look through it.

like image 171
IAmTimCorey Avatar answered Sep 27 '22 22:09

IAmTimCorey


One possible cause of this issue could be the Logging Level. Check if Logging level is set to FATAL and if that is the case try replacing this part of the web.config:

 <log4net>
         .....
         <root>
              <level value="FATAL" /> 
              <appender-ref ref="RollingFileAppender" />
            </root>
         .....
    </log4net>

with this:

<log4net>
    ......
    <root>
         <level value="DEBUG" /> 
           <appender-ref ref="RollingFileAppender" />
       </root>
    ....
</log4net>

Furthemore don't forget to check in web.config section the eventual occurences of some

 <filter type="log4net.Filter.StringMatchFilter">
    <stringToMatch value="test" />
  </filter>

subsection. In this case even though the logging level is set to DEBUG (for example) and you put in your code somethig like:

log.Debug("Db quering...");

it will always return blank but if you write for example:

log.Debug("test: Db quering...");

Try therefore to comment out the filter sections and also this line

  <filter type="log4net.Filter.DenyAllFilter" />

a this point finally you should get it working!!

Hope this helps

like image 36
Fuvizzo Avatar answered Sep 27 '22 21:09

Fuvizzo