将 log4net 包含到使用 .net 4.0 构建的 .net Web 应用程序中

发布于 2024-09-12 00:16:36 字数 1582 浏览 7 评论 0原文

我看到网上有很多很多关于这个问题的帖子,也在 stackoverflow 中,但我没有找到任何方法来解决我的问题。我现在已经尝试了 3 件事,但都不起作用:

  1. 我只是尝试获取从 log4net zip 文件夹中给出的 log4net.dll 以及 bin 目录中的所有源代码。 结果:没有编译错误,但我的 SmtpAppender 只是不发送错误电子邮件。
  2. 所以,我从网上搜索发现它可能与log4net.dll编译的版本有关。这很奇怪,但无论如何,我遇到了一个错误,要求我为程序集生成一个强密钥,这就是我所做的并进行编译,所以我发布了这个项目并获取 log4net.dll 并将其添加到我的项目的引用中。 结果:没有编译错误,但尝试从 Global.asax 行配置时出现 1 个错误:

    protected void Application_Start(object sender, EventArgs e) {
        log4net.Config.XmlConfigurator.Configure();
    }
    

    这是错误:(参见#Ref1)

  3. 因此,我再次从据我所知,某些艾哈迈德·福阿德希望一切顺利。 这是主题。我已经完成了他所说的一切,但我仍然遇到同样的错误(#Ref1)。

有人成功使用 Framework 4.0 将 SmtpAppender 配置到 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 库。这是失败的地方:

// 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

    [...]
}

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 :

  1. 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.
  2. 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)

  3. 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

    [...]
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁的新欢旧爱 2024-09-19 00:16:36

找到它!!我读过这篇文章 Log4Net 和 .NET 4.0 RC ,它只是解决它!

在我的第一篇文章(问题)中,在我尝试过的步骤 3 中,它说要替换 AssemblyInfo.cs 中的某些内容:

他说:“在 AssemblyInfo.cs 中,将部分安全性的部分修改为如下所示:”

  (#)if (!NETCF && !NET_4_0)
  //
  // If log4net is strongly named it still allows partially trusted callers
  //
  [assembly: System.Security.AllowPartiallyTrustedCallers]
  (#)endif

不好了!!您必须删除“!NET_4_0”并用此行替换[程序集]:

  [assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]

SMTPAppender 和 FileAppender 现在对我来说都工作正常!

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!

疏忽 2024-09-19 00:16:36

在部分信任 4.0 网站下使用 log4net v1.2.11 时,您仍然会收到此错误消息,例如:

<system.web>
    <trust level="Medium" />

如果不需要部分信任,请将其更改为:

<system.web>
    <trust level="Full" />

停止错误。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文