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

Techmaster picture Techmaster · Jun 20, 2011 · Viewed 11.5k times · Source

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

Answer

IAmTimCorey picture IAmTimCorey · Jun 21, 2011

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.