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 8252721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:37:55+00:00 2026-06-08T00:37:55+00:00

We are using Log4Net from our ASP.NET MVC3 application, all works fine but we

  • 0

We are using Log4Net from our ASP.NET MVC3 application, all works fine but we would like to see the current username instead of the application pool’s identity in the log files, this is the appender configuration we are using:

<log4net>
    <appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
      <threshold value="ALL" />
      <immediateFlush>true</immediateFlush>
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <encoding value="utf-8" />
      <file value="C:\Logs\MyLogs.log" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <maxSizeRollBackups value="30" />
      <maximumFileSize value="25MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="[%property{log4net:HostName}] - %username%newline%utcdate - %-5level - %message%newline" />
      </layout>
    </appender>
    <root>
      <priority value="ALL" />
      <appender-ref ref="FileAppender" />
    </root>
</log4net>

So it seems like the property: %username is retrieving the value of:

WindowsIdentity.GetCurrent().Name

Instead of what we would need: HttpContext.Current.User

Any idea on how we can solve this easily in the web.config without creating custom properties or additional log4net derived classes? If possible at all otherwise if custom property is the only way we can live with that I guess 🙂 thanks!

  • 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-06-08T00:37:55+00:00Added an answer on June 8, 2026 at 12:37 am

    Replacing %username by %identity should do it. It is working for me in my current project.

    You can learn more about log4net with this excellent tutorial

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

Sidebar

Related Questions

Using log4net we would like to log all calls to our ASP.NET MVC controller
We recently moved all our tests from NUnit to MsTest. We are using Spring.NET
I am having log4net permission issue from ASP.Net 4.0 web application to write to
I'm currently using log4net in my ASP.NET MVC application to log exceptions. The way
I am using log4net and would like to set up a process to notify
We are using log4net to create our logfiles from Windows services, and we are
We are trying to use Log4Net to log from our IIS 6-deployed WCF Application.
I need to do logging in our application and would like to keep the
I'm using log4net to log in my app. My FileAppender is working fine, but
I'm using XSLT to process my ASP.Net web.config file to insert some extra log4net

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.