Reputation: 18916
I saw that there's many, many thread about this on the web, also in stackoverflow, but i didn't find any way to resolve my problem. I've tried 3 things about now and it all didn't works :
So, I've search from web to find that it can be related to the version that the log4net.dll were compile. Which is wierd but anyway, I ran into one error whos asking me to generate a strong key for the assembly and that's what I've done and compile so I release this project and take the log4net.dll and add it to my projet's refereces. Result : No compilation error but 1 error when it is trying to configure from the Global.asax line :
protected void Application_Start(object sender, EventArgs e) {
log4net.Config.XmlConfigurator.Configure();
}
Here's the error : (See #Ref1)
Do anyone succeeded to configure SmtpAppender into a C# VS.net Web Appplication using Framework 4.0 ?
Inheritance security rules violated while overriding member: 'log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden
I've just tried something else. I've open the complete .sln of the log4net application converted with VS.net 2010, added a web project looking exactly the same as my application but in this case, I'm able to debug Log4net library. Here's where it fails :
// If we could not find an alias
if (rep == null)
{
LogLog.Debug("DefaultRepositorySelector: Creating repository [" + repositoryName + "] using type [" + repositoryType + "]");
// Call the no arg constructor for the repositoryType
HERE -> rep = (ILoggerRepository)Activator.CreateInstance(repositoryType); <-- HERE
[...]
}
Upvotes: 2
Views: 4920
Reputation: 121
You'll still get this error message using log4net v1.2.11 under a partial trust 4.0 website eg:
<system.web>
<trust level="Medium" />
If there is no necessity for partial trust, changing this to:
<system.web>
<trust level="Full" />
stops the error.
Upvotes: 4
Reputation: 18916
Find it!! I've read this post Log4Net and .NET 4.0 RC and it simply just solve it!
In my first post (the question), at step 3 of things i've tried, it says to replace something in AssemblyInfo.cs :
He says : "In AssemblyInfo.cs, modified the part for Partial Security to be like this:"
(#)if (!NETCF && !NET_4_0)
//
// If log4net is strongly named it still allows partially trusted callers
//
[assembly: System.Security.AllowPartiallyTrustedCallers]
(#)endif
It's not good!! You must remove the "!NET_4_0" and replace the [assembly] by this line :
[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]
Both SMTPAppender and FileAppender now working fine for me!
Upvotes: 5