问题描述
我可以使用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'salot 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:
更新2:
我误以为测试webapp fileAppender在IIS7.5中工作。这就是:测试webapp fileAppender和AdoDotNetAppender都在Cassini / IIS开发中工作,但在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,但我作为nonAdmin登录到Windows 7。此外,我正在运行Windows 7 Home Premium,而不是Professional。
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" />
如果用户是管理员,则可以。如果是我,而不是管理员,那就不是。所以这是一个权限问题。但我确实授予了EVERYONE以前写入文件的目录的权限,但它没有工作,因此在其他地方有一个权限设置。此外,虽然FileAppender现在可以使用模拟,但AdoNetAppender stil不在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中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!