namasayadin
namasayadin

Reputation: 45

Log4net does not write log

I have a problem regarding log file in my system in asp.net using castle framework. The log file was not updated. This is an old system since 2011 i guess and the last date the log updated is on 2013.

There is another similar base code using the same web config can write the log file but after i make the log folder permission into everyone. I have try the same thing at a staging server for the old system but still the log file is not written. Been looking at some info here but still cannot find the root cause.

Below is the code:

<log4net>
<appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net">
  <param name="File" value="Logs\LogFile.log" />
  <param name="AppendToFile" value="true" />
  <param name="RollingStyle" value="Size" />
  <param name="MaxSizeRollBackups" value="10" />
  <param name="MaximumFileSize" value="10000KB" />
  <param name="StaticLogFileName" value="true" />
  <layout type="log4net.Layout.PatternLayout,log4net">
    <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}> - %m%n" />
  </layout>
  <layout type="log4net.Layout.PatternLayout">
    <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}>%n - %m%n" />
  </layout>
</appender>

Hope someone can give some insight.

[UPDATE]

There is actually the fucntion of Application_Start (if it is asp.net) like above. log4net.Config.XmlConfigurator.Configure(); but it was commented by previous dev. When i uncomment it, a new error will appear.

It is because of this code below:

try
        {
            SingleSignOnHelper<Staff> singleSignOnHelper = ServiceLocator.Current.GetInstance<SingleSignOnHelper<Staff>>();
            windowsAuthSucceeded = singleSignOnHelper.TryAuthenticateWithWindowsAuthentication(Context);
            loginPageUrl = singleSignOnHelper.LoginPageUrl;
        }
        catch (Exception ex)
        {
            if (m_log.IsErrorEnabled) m_log.Error("Error while trying to authenticate user using Windows authentication", ex);
            throw;
        }

        if (!windowsAuthSucceeded)
            Context.Response.Redirect(loginPageUrl);
    }
}

Upvotes: 0

Views: 784

Answers (1)

onur
onur

Reputation: 374

 void Application_Start(object sender, EventArgs e)
    {
        log4net.Config.XmlConfigurator.Configure();
}

You should call a function in Application_Start (if it is asp.net) like above. log4net.Config.XmlConfigurator.Configure();

Upvotes: 3

Related Questions