Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 879713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:58:40+00:00 2026-05-15T11:58:40+00:00

I am able to write to a log file using log4net and Cassini/IIS dev

  • 0

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.

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

The trust level is full according to IISM.

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

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");

Any clues?

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

EDIT:

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?

UPDATE:

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: Request for the permission of type ‘System.Configuration.ConfigurationPermission, System.Configuration…’ failed.

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.

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.

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

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.

UPDATE 3:

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

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

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>

to the AdoNetAppender section, but still getting silent fail.

I added a bounty for anyone who can help me get the AdoNetAppender working with IIS7.5.

UPDATE 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

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:58:41+00:00Added an answer on May 15, 2026 at 11:58 am

    I finally got it working, i added

    <trust level="Full" />
    

    to system.web.

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am able to write a data frame to an excel file, using the
When running a progress-4gl program, I am able to write to a log file
I can't write to the event log with NLog. I've been able to write
I have a file (called 'log.html') on my iis7.5 server that I would like
I'm working with a WCF web service project and using log4net, but can't get
When I would be able to write : <asp:TextBox id=Input runat=server/> <asp:Button onclick=<% Input.Text='my
I am using memory mapped IO for an index file, but the problem is
I'm transferring a file using ftp in Delphi. I am able to connect to
I have a windows service that writes out log file entries to an XML
I am trying to upload a file to an FTP-server using a URLConnection. There

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.