包括log4net的建成将使用.NET 4.0的.NET Web应用程序应用程序、NET、log4net、Web

2023-09-07 13:54:49 作者:吸煙傷肺゛想妳傷心

我看到有关于这个在网络上很多,多线程,也计算器,但我没有找到任何办法来解决我的问题。我试过3有关的事情,现在,这一切都没有作品:

我只是试图让从log4net的压缩文件夹给所有的源$ C ​​$ C的bin目录中的log4net.dll卫生组织。 结果:没有编译错误,但我SmtpAppender就是不将错误发送电子邮件

所以,我从网上搜索发现,它的可以的涉及到该log4net.dll是编译的版本。这是奇怪的,但是无论如何,我跑成一个错误卫生组织问我生成强键的组装,这就是我所做的事情和编译,所以我发布这个项目,并采取log4net.dll并将其添加到我谟的refereces。 结果:没有编译错误,但是,当它试图从在Global.asax线配置1错误:

 保护无效的Application_Start(对象发件人,EventArgs的){
    log4net.Config.XmlConfigurator.Configure();
}
 

下面的错误:(见#参考文献1)

所以,再一次,我发现从某艾哈迈德·福阿德卫生组织这个线程,据我,在寻找到工作正常。 这里的线程。我所做的一切,他说,但我还是遇到了同样的错误(#参考文献1)。

难道有人成功配置SmtpAppender到使用框架4.0的C#VS.net的Web应用项目?

参考文献1

  而覆盖件

继承安全规则违反: 'log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)。压倒一切的方法必须与方法的安全辅助功能相匹配的安全访问被重写

附加信息(审查#1)

我刚刚试过别的东西。我已经打开转换与VS.net 2010 log4net的应用程序的完整的.sln,增加了一个Web项目看完全一样,我的应用程序,但在这种情况下,我能够调试log4net的图书馆。这里就是失败:

  //如果我们无法找到一个别名
如果(代表== NULL)
{
    LogLog.Debug(DefaultRepositorySelector:创建库[+ repositoryName +]使用类型[+ repositoryType +]);

    //调用无参构造的repositoryType
    这里 - >代表=​​(ILoggerRepository)Activator.CreateInstance(repositoryType); <  - 这里

    [...]
}
 

解决方案

搜寻!我读过这篇文章http://stackoverflow.com/questions/2279896/log4net-and-net-4-0-rc它只是简单地解决这个问题!

Log4Net的使用之winform

在我的第一篇文章(的问题),在事情我已经试过第3步,它说要替换一些在AssemblyInfo.cs中:

他说:在AssemblyInfo.cs中,修改了部分偏安全是这样的:

 (#)如果(NETCF&安培;!&安培;!NET_4_0)
  //
  //如果log4net的强烈命名它仍然允许部分信任的调用方
  //
  [总成:System.Security.AllowPartiallyTrustedCallers]
  (#)ENDIF
 

这不是好!您必须删除NET_4_0!,并通过这条线替换[装配]:

  [总成:System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)
 

无论SMTPAppender和FileAppender现在的工作对我罚款!

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 :

I've simply tried to get the log4net.dll whos given from the log4net zip folder with all source code in the bin directory. Results : No compilation error, but my SmtpAppender just don't send errors email.

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)

So, again, I've found out this thread from a certain Ahmed Fouad whos, according to me, were looking to works fine. Here's the thread. I've done everything he says but I still run into the same error (#Ref1).

Do anyone succeeded to configure SmtpAppender into a C# VS.net Web Appplication using Framework 4.0 ?

Ref1

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

Additional informations (Review #1)

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

    [...]
}

解决方案

Find it!! I've read this post http://stackoverflow.com/questions/2279896/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!