log4net - Appenders 在 IIS7.5 中不起作用 [英] log4net - Appenders not working in IIS7.5

查看:30
本文介绍了log4net - Appenders 在 IIS7.5 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 log4net 和 Cassini/IIS 开发服务器写入日志文件,但是当我使用 IIS7.5 时,我无法写入文件.

I am able to write to a log file using log4net and Cassini/IIS dev server, but when I use IIS7.5, I can't write out to a file.

最初,我遇到了一个安全异常,所以我添加了 requirePermission="false" 并且异常消失了,但没有创建文件.

Initially, I got a security exception, so I added requirePermission="false" and the exception went away but no file was created.

根据IISM,信任级别为满.

The trust level is full according to IISM.

我无法在我自己的机器上使用它,我想知道当我转移到 ISP (discountASP) 时会发生什么.

I can't get this working on my own machine, I'm wondering what's going to happen when I transfer to an ISP (discountASP).

这是 log4net 设置:

Here's the log4net setup:

<configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false"  />
</configSections>

<log4net>
    <appender name="FileAppender" type="log4net.Appender.FileAppender">
        <file value="log-file.txt" />
        <appendToFile value="true" />
        <encoding value="utf-8" />
        <layout type="log4net.Layout.SimpleLayout" />
    </appender>
    <root>
        <level value="DEBUG" />
        <appender-ref ref="FileAppender" />
    </root>
</log4net>

C#

log4net.Config.XmlConfigurator.Configure();
ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Log.Info("This is a test");

有什么线索吗?

ASP.NET 3.5、VS2008、Windows 7、IIS7.5、log4net 1.2.10

ASP.NET 3.5, VS2008, Windows 7, IIS7.5, log4net 1.2.10

我使用了在 Cassini 中运行的测试 Web 应用程序,并在 IIS7.5 中运行它并且它工作正常,因此我的 Web 应用程序有一些特定的东西阻止了 log4net 运行.有很多事情在里面,ELMAH,输出缓存,AJAX 控制工具包,表单身份验证,ssl,url 重写等......除了将每个添加到测试应用程序中之外,是否有更好的方法来找出导致 log4net 的原因上班?

I used the test web app that ran in Cassini and ran it in IIS7.5 and it worked so there's something specific to my web application that's preventing log4net from running. There's alot going on in it, ELMAH, output caching, AJAX Control Toolkit, forms authentication, ssl, url rewriting, etc... Other than adding each of those on to the test app, is there a better way to figure out what's causing log4net to work?

更新:

我使用 AdoNetAppender 来避免文件权限问题,但仍然得到相同的结果.AdoNetAppender 适用于在 Cassini 和 IIS 上运行的测试应用程序,但不适用于我的 Web 应用程序.得到以下异常:

I used the AdoNetAppender to stay away from the file permission problems and am still getting the same result. The AdoNetAppender works for the test app running on Cassini and IIS, but it doesn't work on my web app. Getting the following exception:

System.Security.SecurityException:请求类型为System.Configuration.ConfigurationPermission, System.Configuration..."的权限失败.

System.Security.SecurityException: Request for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration...' failed.

更新 2:我误认为测试 webapp fileAppender 在 IIS7.5 中工作.这是发生的事情:测试 webapp fileAppender 和 AdoDotNetAppender 都可以在 Cassini/IIS dev 中工作,但不能在 IIS7.5 中工作.所以我认为是 IIS 的问题,而不是我的 webapp.

UPDATE 2: I was mistaken that the test webapp fileAppender worked in IIS7.5. This is what happens: The test webapp fileAppender and AdoDotNetAppender both work in Cassini/IIS dev, but not in IIS7.5. So I think it's IIS that's the problem, not my webapp.

注意.我以管理员身份运行 VS2008,但以非管理员身份登录 Windows 7.另外,我运行的是 Windows 7 家庭高级版,而不是专业版.

Note. I am running VS2008 as Admin, but am logged into Windows 7 as a nonAdmin. Also, I'm running Windows 7 Home Premium, not Professional.

我授予 NETWORK SERVICE 对 Web 根目录的完全权限,但仍然没有创建文件.还给了每个人完全的权限,没有文件.

I granted NETWORK SERVICE full permission to the web root directory and still no file created. Also gave EVERYONE full permission, no file.

由于 adoDotNetAppender 也不起作用(但在开发 IIS 中起作用),我认为除了文件权限之外可能还有另一个问题.

Since the adoDotNetAppender didn't work either (but did in dev IIS), I think there may be another issue in addition to the file permissions.

更新 3:

我让它在 IIS7 上为 FileAppender 工作.如果我添加这个:

I got it to work for the FileAppender on IIS7. If I add this:

<identity impersonate="true"
    userName="zzz"
    password="yyy" />

如果用户是管理员,它就可以工作.如果是我而不是管理员,则不会.所以这是一个权限问题.但是我确实授予了每个人对该文件之前写入的目录的权限,但它不起作用,所以在其他地方有一个权限设置.此外,虽然 FileAppender 现在可以使用模拟,但 AdoNetAppender 仍然不在 IIS7 中.我尝试添加:

and if the user is an admin, it works. If it's me, not an admin, it doesn't. So it's a permissions issue. But I did grant EVERYONE rights to the directory the file is written to before and it didn't work, so there's a permission setting elsewhere. Also, while the FileAppender now works with the impersonation, the AdoNetAppender stil doesn't in IIS7. I tried adding:

<securityContext type="log4net.Util.WindowsSecurityContext">
    <userName value="zzz" />
    <password value="yyy" />
    <domain value="aaa" />
</securityContext>

到 AdoNetAppender 部分,但仍然沉默失败.

to the AdoNetAppender section, but still getting silent fail.

我为任何可以帮助我让 AdoNetAppender 与 IIS7.5 一起工作的人悬赏.

更新 4:

我终于掌握了堆栈跟踪.这是:

I finally got a hold of the stack trace. Here it is:

log4net:ERROR [AdoNetAppender] Failed in DoAppend
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
       at log4net.Util.LogicalThreadContextProperties.GetProperties(Boolean create)
       at log4net.Core.LoggingEvent.CreateCompositeProperties()
       at log4net.Core.LoggingEvent.CacheProperties()
       at log4net.Core.LoggingEvent.FixVolatileData(FixFlags flags)
       at log4net.Core.LoggingEvent.set_Fix(FixFlags value)
       at log4net.Appender.BufferingAppenderSkeleton.Append(LoggingEvent loggingEvent)
       at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent loggingEvent)
The action that failed was:
LinkDemand
The type of the first permission that failed was:
System.Security.Permissions.SecurityPermission
The Zone of the assembly that failed was:
MyComputer

我打开了 SQL Profiler,但没有任何东西进入 SQL Server.此外,SQL Server 帐户具有执行插入操作的适当权限.此外,我删除了 SecurityContext 部分,因为 log4net 无法识别其中的一部分.

I had the SQL Profiler on and nothing made it to SQL Server. Also, the SQL Server account has the proper privileges to do the insert. Also, I removed the SecurityContext section as log4net did not recognize part of it.

推荐答案

我终于搞定了,我补充了

I finally got it working, i added

<trust level="Full" />

到 system.web.

to system.web.

使用中,AdoNetAppender 停止工作,但 FileAppender 仍然适用于中和高.

With medium, the AdoNetAppender stops working, but the FileAppender still works for medium and high.

这篇关于log4net - Appenders 在 IIS7.5 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆