log4net logging problem

Posted by Dotnet_user on Stack Overflow See other posts from Stack Overflow or by Dotnet_user
Published on 2010-04-27T15:26:28Z Indexed on 2010/04/27 15:33 UTC
Read the original article Hit count: 431

Filed under:
|
|

Hello everyone,

I'm not sure if this is the right forum to post this question. But I'm just hoping someone here might have used log4net in the past, so hoping to get some help.

I'm using log4net to log my exceptions. The configuration settings look like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
  <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
 </configSections>
 <log4net debug="false">
  <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
   <file value="C:\Logs\sample.log" />
   <appendToFile value="true"/>
   <rollingStyle value="Size"/>
   <maxSizeRollBackups value="10"/>
   <maximumFileSize value="10MB"/>
   <staticLogFileName value="true"/>
   <layout type="log4net.Layout.PatternLayout">
     <conversionPattern value="%-5level %date %logger.%method[line %line] - %message%newline"/>
   </layout>
 </appender>
 <root>
  <level value="INFO"/>
  <appender-ref ref="RollingLogFileAppender"/>
 </root>
</log4net>
</configuration>

I started out by adding this configuration to web.config, but I got an error (VS studio could not find a schema for log4net-"Could not find schema information for the element log4net"). So I followed this link (http://stackoverflow.com/questions/174430/log4net-could-not-find-schema-information-messages) and configured my settings in a separate xml file and added the following line of code in my AssemblyInfo.cs:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "xmlfile.xml", Watch = true)]

And in the actual code, I placed this line:

public void CreateUser(String username, String password)
{
 try
 {
  log.Info("Inside createuser");
  //code for creating user
 }
 catch(exception e)
 {
  log.Info("something happened in create user", e);
 }
}

The problem is that the log file is not being created. I can't see anything inside C:\Logs. Can anybody tell me what I'm doing wrong here?

Any suggestions/inputs will be very helpful.

Thank you all in advance.

© Stack Overflow or respective owner

Related posts about log4net

Related posts about c#