niknowj
niknowj

Reputation: 1037

log4net is not logging to log file?

Log4net is not logging to file, Here is my code and config part.

My asp.net Button Click

public partial class _Default : System.Web.UI.Page
{
    private static readonly log4net.ILog log = log4net.LogManager.GetLogger
(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        log.Error("TestError");
    }
}

My Web.Config file

  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
  </configSections>
  <log4net>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="LogFileAppender"/>
    </root>
    <appender name="LogFileAppender” type=”log4net.Appender.RollingFileAppender" >
      <param name="File" value="C:\log.txt"/>
      <param name="AppendToFile" value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" />
      </layout>
    </appender>
  </log4net>

Upvotes: 2

Views: 265

Answers (1)

Tamim Al Manaseer
Tamim Al Manaseer

Reputation: 3724

My guess its a permission issue, related to writing to C:\log.txt, try a different location.

Try to enable log4net tracing to make sure its a permission denied issue.

Here is a link from Phil Haack's blog that tells you how to enable tracing on log4net.

Upvotes: 4

Related Questions