[Prev] Thread [Next]  |  [Prev] Date [Next]

RE: Logger not working in an ASP.Net environment only works with full trust Venkatasamy, Vanitha Wed Mar 14 12:01:41 2012

 The error seems new to me, because I had encountered lot of issues while 
implementing the log4Net in my app.

Please check the below option , it might help you..
1.In your web.config enable the log4net enable
<add key="log4net.Internal.Debug" value="true"/>
After </system.web>
    <trace autoflush="true">
        <add name="textWriterTraceListener"
           initializeData="c:\\logerror.log" />

2. <configSections>
    <section name="log4net" 
log4net,Version=, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a"/>

3.In you config ,is this the full path

      <file value="logfile.txt" />

make sure you have full write permission.

4.I was using EventLog appender , so I gave permission to create the log for 
the users.

using log4net;
using log4net.Config;
using System.Reflection;
using System.Diagnostics.Eventing;

public static readonly ILog log = 

instead of
log = 

Let me know if it helps.


From: Dennis Minderhoud [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 14, 2012 2:10 PM
Subject: Logger not working in an ASP.Net environment only works with full trust

I've made a simple .NET 4 Web Application in VS2010, and added a reference to 
log4net (latest).

In this project I've made a Logger class:
public static class Logger
    private static readonly log4net.ILog log;

    static Logger()
        try {
            log = 

        catch (Exception e)

    public static void LogInfo(string information)

    public static void LogError(string erroMessage, Exception ex)
        log.Error(erroMessage, ex);

    public static void LogWarnings(string warningText)

    public static void Fatal(string fatalText)

When I call this Logger class (Logger.Fatal("Test");) in a Full trust 
environment, everything works correct. However, when I change the trust level 
to High (or Medium) it fails with the following exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the 
target of an invocation. ---> System.TypeLoadException: Inheritance security 
rules violated while overriding member: 
 System.Runtime.Serialization.StreamingContext)'. Security accessibility of the 
overriding method must match the security accessibility of the method being 
   at log4net.Repository.Hierarchy.Hierarchy..ctor(ILoggerFactory loggerFactory)
   at log4net.Repository.Hierarchy.Hierarchy..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean 
publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& 
ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean 
skipCheckThis, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean 
skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at log4net.Core.DefaultRepositorySelector.CreateRepository(String 
repositoryName, Type repositoryType)
   at log4net.Core.DefaultRepositorySelector.CreateRepository(Assembly 
repositoryAssembly, Type repositoryType, String repositoryName, Boolean 
   at log4net.Core.DefaultRepositorySelector.CreateRepository(Assembly 
repositoryAssembly, Type repositoryType)
   at log4net.Core.DefaultRepositorySelector.GetRepository(Assembly 
   at log4net.Core.LoggerManager.GetRepository(Assembly repositoryAssembly)
   at log4net.Config.XmlConfigurator.Configure()
   at UtilClasses.Logger..cctor() in c:\users\***\documents\visual studio 
2010\Projects\TestLogging\TestLogging\Default.aspx.cs:line 35

When I include the log4net project to the solution, I get the exception when 
creating an instance of the default LogRepository:

rep = (ILoggerRepository)Activator.CreateInstance(repositoryType); on line 412 
of DefaultRepositorySelector.cs

this is my web.config:

<?xml version="1.0"?>


    <section name="log4net" 
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <compilation debug="true" targetFramework="4.0" />
    <trust level="High" />
  <log4net debug="true">
    <appender name="RollingFileAppender" 
      <file value="logfile.txt" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <datePattern value="yyyy-MM-dd" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date{dd-MM-yyyy HH:mm:ss,fff} [%-2p] - %C.%M 
- %m%n" />


      <level value="ALL" />
      <appender-ref ref="RollingFileAppender" />
     <modules runAllManagedModulesForAllRequests="true"/>

Other people suggest to add requirePermission="false" to the section, but then 
the debugger won't attach to the application pool.

I hope someone can help me out of this problem.


Dennis Minderhoud


This message contains Devin Group confidential information and is intended only 
for the individual named. If you are not the named addressee you should not 
disseminate, distribute or copy this e-mail.
Please notify the sender immediately by e-mail if you have received this e-mail 
in error and delete this e-mail from your system. E-mail transmissions cannot 
be guaranteed secure, error-free and information could be intercepted, 
corrupted, lost, destroyed, arrive late, incomplete, or contain viruses. The 
sender therefore does not accept liability for errors or omissions in the 
contents of this message which may arise as result of transmission. If 
verification is required please request hard-copy version.