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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:57:42+00:00 2026-05-26T14:57:42+00:00

I need some idea to implement the following requirement in the web application .

  • 0

I need some idea to implement the following requirement in the web application .

I am using log4net in a custom dll to log the errors. I completed the log4net implementation and its working fine.[aspx errors are logged in EventLog and the asp errors are logged in FileAppender] .All the loggerError() methods are in the custom dll.

Now i want to monitor the logging,suppose if there is a situation like the loggerError() method is called more than 20 times in just 5 mins bse of Fatal error or database is down,then i want to track that and send email to admin.

My ideas,

1.Set a timer and count variable to track the number of hits .

2.After each hit check the number of hits and the secs.

3.If it exceeds the threshold limit .then trigger the email…

Not sure how this will work or is there any other way to achieve it.

Thanks in advance

  • 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-26T14:57:43+00:00Added an answer on May 26, 2026 at 2:57 pm

    I would suggest writing your own Appender to house this logic. The Appender could be used as a wrapper for another Appender (maybe the SmtpAppender?). The ForwardingAppender looks like a good example of a “wrapper” Appender. As each log message comes in, apply your timing and severity logic. If your criteria are met, forward the message to the “wrapped” Appender.

    Alternatively this Appender could contain its own logic for generating and sending email (or whatever notification scheme you would like to use).

    This Appender could be configured via the standard log4net configuration mechanism (app.config, separate config, etc) so the time span, error level, error count, could be configurable.

    Here is an idea for how something like this might be implemented as an Appender:

    public class MultiThresholdNotifyingAppender : AppenderSkeleton
    {
      private Queue<LoggingEvent> loggingEventQueue = new Queue<LoggingEvent>();
    
      private DateTime windowStart;
    
      public Level LevelThreshold { get; set; }
      public TimeSpan WindowLength { get; set; }
      public int HitThreshold { get; set; }
    
      public void Append(LoggingEvent loggingEvent)
      {
        if (loggingEvent.Level < LevelThreshold) 
        {
          if (loggingEventQueue.Count == 0) return;
    
          if (loggingEvent.TimeStamp - windowStart) >= WindowLength)
          {
            //Error level is less than threshold and the time window has elapsed.  Remove any queued LoggingEvents
            //until all LoggingEvents in the queue fall within the time window.
            while (loggingEventQueue.Count > 0 && loggingEventQueue.Peek().TimeStamp - windowStart >= WindowLength)
            {
              loggingEventQueue.Dequeue();
            }
    
            windowStart = loggingEventQueue.Peek().TimeStamp;
    
            return;
          }
        }
    
        //If we got here, then the Error level is >= the threshold.  We want to save the LoggingEvent and we MIGHT
        //want to notify the administrator if the other criteria are met (number of errors within time window).
        loggingEventQueue.Enqueue(loggingEvent);
    
        //If this is the first error in the queue, start the time window.
        if (loggingEventQueue.Count == 1) windowStart = loggingEvent.TimeStamp;
    
        //Too few messages to qualify for notification.
        if (loggingEventQueue.Count < HitThreshold - 1) return; 
    
        //Now we're talking!  A lot of error messages in a short period of time.    
        if (loggingEvent.TimeStamp - windowStart >= WindowLength)
        {
          //Build a notification message for the administrator by concatenating the "rendered" version of each LoggingEvent.
          string message = string.Join(Enviroment.NewLine, loggingEventQueue.Select(le => le.RenderedMessage));
          SendTheMessage(message);
        }
    
        //After sending the message, clear the LoggingEvents and reset the time window.
        loggingEventQueue.Clear();      
        windowStart = loggingEvent.TimeStamp;
      }
    
      public void Append(LoggingEvent[] loggingEvents)
      {
        foreach (var le in loggingEvents)
        {
          Append(le);
        }
      }
    }
    

    The idea is to configure your threshold (maybe along with your notification method) values on the appender. Configure your loggers to send their messages to this appender, in addition to any other appenders you want to send them to (EventLog, File, etc). As each logging message comes through, this appender can examine it in the context of the configured threshold values and send the notification as necessary.

    There could very well be threading issues in this code (unless log4net handles that for you), so you might need a lock when accessing the queue.

    Note that this code has not been compiled nor has it been tested.

    See this link for some sample custom Appenders in the log4net repository:

    http://svn.apache.org/viewvc/logging/log4net/trunk/examples/net/2.0/Appenders/

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

Sidebar

Related Questions

I have three buttons and need to save some data. I have a idea,
Need some guidance figuring out what went wrong. I've been using mysql, phpmyadmin for
Need some best practice advice here... Navigation based application. Root view is a UITableView
I want to implement copy protection for opengl render, here are some idea, none
I need some idea how to write a C++ cross platform implementation of a
Lyrics: I try to implement a task pool over MPI. So I need some
I want to implement following logic in my SQL query: If some date is
Need some help about with Memcache. I have created a class and want to
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview

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.