How to do configuration in assembly.cs file for log4net implementation?
-----------------------------------------------------------------------

                 Key: LOG4NET-303
                 URL: https://issues.apache.org/jira/browse/LOG4NET-303
             Project: Log4net
          Issue Type: Bug
         Environment: .net 3.5 ..Implementing log4net for aspx and asp pages
            Reporter: Vanitha


I am trying to implement the log4net. In my project ,i am referring a dll 
project,which has the log4net implementation and i am calling the dll from from 
my asp number. 
 
  The call is successful from asp to dll method and the logger is created just 
fine.
 

    private static readonly ILog log = 
LogManager.GetLogger(typeof(ErrorLogging).Name);

But the problem is the logger is not enabled. I mean 
IsErrorEnabled/IsDebugEnabled are false.

The confusing part to me is assembly.cs,in which the place where we mention the 

    [assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "log4net", 
Watch = true)]
    // This will cause log4net to look for a configuration file
    // called TestApp.exe.log4net in the application base
    // directory (i.e. the directory containing TestApp.exe)
    // The config file will be watched for changes.

So ,do i need to create a file with .log4net extension ,if so i tried and its 
not working.
And not working from my web.config also. 

Please see my web.config code 

  

    <log4net debug="true">
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
      <param name="LogName" value="PortalWebLog" />
      <param name="ApplicationName" value="Portal" />
      <eventId value="6" />
      <eventCategory value="10" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger 
[%property{NDC}] - %message%newline" />
      </layout>
    </appender>
    <root>
      <priority value="DEBUG" />
      
      <appender-ref ref="EventLogAppender" />
    </root>
  </log4net>

    <configSections>
    <section name="log4net" 
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>

And the dll method ,where i am accesing the log 

    log4net.Config.XmlConfigurator.Configure();
            log4net.ThreadContext.Properties["EventID"] = 6;

            String tempdata=string.Empty;

            if (!System.Diagnostics.EventLog.SourceExists(sourceName))
            {
                tempdata = sourceName + logName + objErr + strBotListPath;
                System.Diagnostics.EventLog.CreateEventSource(sourceName, 
logName);
            }
            else
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("This is a DEBUG level message. The most VERBOSE 
level.");
                    log.Info("Extended information, with higher importance than 
the Debug call");
                    log.Warn("An unexpected but recoverable situation 
occurred");
                    tempdata = "Source already exits";
                }
                else
                {
                    tempdata = "Source already exits,but debug not enabled";
                }
            }

The output is 
 

    Source already exits,but debug not enabled 

it works fine while doing in Global.asax file,but these issues are only 
accessing the external dll. So my questiona are in assembly.cs like where the 
.log4net config file should be placed?.Or am i doing anything wrong in the 
config part... 

Please give me some input...

Thanks

 **UPDATE**
After removing the below line 

    [assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "log4net", 
Watch = true)]

and changing the line,by placing the log4net.config in 
C:\windows\system32\inetsrv,the error log is enabled.**But i am not seeing any 
errors in the eventLog its empty**

     log4net.Config.XmlConfigurator.ConfigureAndWatch(new 
FileInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase+"log4net.config"));




--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to