Question

I am creating an add on(Class library (.dll)) for internet explorer 9.0. And want to use log4net dll for logging.

I am using the following

  • .NET 4.0
  • Visual Studio 2010
  • log4net Version - 1.2.11.0 (for .Net 4.0)

I have created an app.config file and here is the cofiguration that I am using,

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="log4net"  
        type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, 
        Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a"/>
    </configSections>

    <log4net>
        <appender name="RollingLogFileAppender" 
        type="log4net.Appender.RollingFileAppender">
           <param name="File" value="D:\\Temp\\Temp.log"/>
           <param name="AppendToFile" value="true"/>
           <param name="MaxSizeRollBackups" value="30"/>
           <param name="MaximumFileSize" value="10MB"/>
           <param name="RollingStyle" value="Date" />
           <param name="StaticLogFileName" value="true"/>
           <param name="DatePattern" value="yyyyMMdd" />
           <layout type="log4net.Layout.PatternLayout">
               <param name="Header" value="[Header]\r\n"/>
               <param name="Footer" value="[Footer]\r\n"/>
               <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - (%F:%L) 
               %m%n"/>
           </layout>
        </appender>
        <root>
           <level value="ALL"/>
           <appender-ref ref="RollingLogFileAppender"/>
        </root> 
    </log4net>
</configuration>

Added the following code line to AssemblyInfo.cs file

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

Added the following code line to DocumentComplete event handler. which fires upon internet explorer page load.

log4net.Config.XmlConfigurator.Configure();

when my add on is enabled and running . I could not see any log getting created at the specified path "D:\Temp\Temp.log". I am bit confused.

Any help will be greatly appreciated.

Thanks

Was it helpful?

Solution

Thanks a lot for all the responses

The problem is with internet explorer running in protected mode. Internet explorer running in protected mode restricts add on's writing files to the disk.

One more change I did to my config is to add the following line to Assembly.cs file

[assembly: log4net.Config.XmlConfigurator(ConfigFile =  "C:\\Program 
Files\\Temp\\app.config", Watch = true)]

OTHER TIPS

I guess your are running an application, then you should add your code to the exe its app.config. If you are using a web application add the config to the web.config file. I would also check and change the double slashes in:

 <param name="File" value="D:\Temp\Temp.log"/>

When you are running as a webapplication, you need to check the access rights of the app pool user to the D:\Temp\ path (full access).

If you use the attribute in your assambly, you do not need to call:

log4net.Config.XmlConfigurator.Configure();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top