Note that there are some explanatory texts on larger screens.

plurals
  1. POlog4net - Appenders not working in IIS7.5
    text
    copied!<p>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.</p> <p>Initially, I got a security exception, so I added <code>requirePermission="false"</code> and the exception went away but no file was created. </p> <p>The trust level is full according to IISM.</p> <p>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).</p> <p>Here's the log4net setup:</p> <pre class="lang-xml prettyprint-override"><code>&lt;configSections&gt; &lt;section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" /&gt; &lt;/configSections&gt; &lt;log4net&gt; &lt;appender name="FileAppender" type="log4net.Appender.FileAppender"&gt; &lt;file value="log-file.txt" /&gt; &lt;appendToFile value="true" /&gt; &lt;encoding value="utf-8" /&gt; &lt;layout type="log4net.Layout.SimpleLayout" /&gt; &lt;/appender&gt; &lt;root&gt; &lt;level value="DEBUG" /&gt; &lt;appender-ref ref="FileAppender" /&gt; &lt;/root&gt; &lt;/log4net&gt; </code></pre> <p>C#</p> <pre class="lang-cs prettyprint-override"><code>log4net.Config.XmlConfigurator.Configure(); ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); Log.Info("This is a test"); </code></pre> <p>Any clues?</p> <p>ASP.NET 3.5, VS2008, Windows 7, IIS7.5, log4net 1.2.10</p> <p><strong>EDIT:</strong></p> <p>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?</p> <p><strong>UPDATE:</strong></p> <p>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:</p> <blockquote> <p>System.Security.SecurityException: Request for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration...' failed.</p> </blockquote> <p><strong>UPDATE 2:</strong> 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. </p> <p>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. </p> <p>I granted NETWORK SERVICE full permission to the web root directory and still no file created. Also gave EVERYONE full permission, no file.</p> <p>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.</p> <p><strong>UPDATE 3:</strong></p> <p>I got it to work for the FileAppender on IIS7. If I add this:</p> <pre class="lang-xml prettyprint-override"><code>&lt;identity impersonate="true" userName="zzz" password="yyy" /&gt; </code></pre> <p>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:</p> <pre class="lang-xml prettyprint-override"><code>&lt;securityContext type="log4net.Util.WindowsSecurityContext"&gt; &lt;userName value="zzz" /&gt; &lt;password value="yyy" /&gt; &lt;domain value="aaa" /&gt; &lt;/securityContext&gt; </code></pre> <p>to the AdoNetAppender section, but still getting silent fail. </p> <p><strong>I added a bounty for anyone who can help me get the AdoNetAppender working with IIS7.5.</strong></p> <p><strong>UPDATE 4:</strong></p> <p>I finally got a hold of the stack trace. Here it is:</p> <pre><code>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 </code></pre> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload