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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:51:46+00:00 2026-05-14T14:51:46+00:00

I’m using log4net to log my web app’s progress, using Log4PostSharp to AOP-injectify all

  • 0

I’m using log4net to log my web app’s progress, using Log4PostSharp to AOP-injectify all methods. This has the desired effect of logging (almost) everything and is fine.

I now have a requirement to log JUST Page_Load methods to a file / console. I can obviously hamstring the log4postsharp class to do that, but then I’d be losing all the other logging.

I’ve been looking at filters in log4net, starting with the StringMatch filter, but that only looks at the message being logged, and I’m after the method name. This put me onto the PropertyFilter, but still with no joy. My log4net.config snippet is thus:

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
  <filter type="log4net.Filter.PropertyFilter">
    <key value="LocationInfo.MethodName"/>
    <stringToMatch value="Page_Load"/>
  </filter>
  <filter type="log4net.Filter.DenyAllFilter" />
  <file value="d:\\xxxx\\yyyyy\\zzzzLog"/>

As you can see, I’m trying to key into the MethodName of the logging event via LocationInfo, but I’m still getting everything logged. EDIT: As mentioned in the comments, I’ve now included the DenyAllFilter that I added after RTFM 😉

Can anyone assist?

Thank you,

Mike K.

  • 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-14T14:51:46+00:00Added an answer on May 14, 2026 at 2:51 pm

    As far as I can tell log4net does not know a property LocationInfo.MethodName. I am not using Log4PostSharp, so I cannot tell for sure if Log4PostSharp would create this property.

    I would write my own filter like this to filter by method names (regex part omitted):

    public class MethodNameFilter : StringMatchFilter
    {       
         override public FilterDecision Decide(LoggingEvent loggingEvent) 
         {
             if (loggingEvent == null)
             {
                  throw new ArgumentNullException("loggingEvent");
             }
    
             var locationInfo = loggingEvent.LocationInformation;
    
             // Check if we have been setup to filter
             if (locationInfo == null || (m_stringToMatch == null && m_regexToMatch == null))
             {
                 // We cannot filter so allow the filter chain
                 // to continue processing
                  return FilterDecision.Neutral;
             }
    
             if (m_stringToMatch != null)
             {
                 // Check substring match
                 if (locationInfo.MethodName.IndexOf(m_stringToMatch) == -1) 
                 {
                      // No match, continue processing
                      return FilterDecision.Neutral;
                 }
    
                 // we've got a match
                 if (m_acceptOnMatch) 
                 {
                      return FilterDecision.Accept;
                 } 
                 return FilterDecision.Deny;
             }
             return FilterDecision.Neutral;
        }
    } 
    

    Note: Accessing LocationInfo is expensive and can have a noticeable effect on performance. You could consider to modify Log4PostSharp to extract the method name during weaving and store it in some property. In that case you could use the property filter as you intended and you would not have any impact on performance. Not sure if this really works but I would expect that this is possible.

    The configuration would look something like this:

    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
         <filter type="YourNameSpace.MethodNameFilter">
             <stringToMatch value="Page_Load"/>
         </filter>
         <filter type="log4net.Filter.DenyAllFilter" />
         <file value="d:\\xxxx\\yyyyy\\zzzzLog"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the

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.