Click here to Skip to main content
15,879,535 members
Articles / Web Development / ASP.NET

ASP.NET Health Monitoring - Building an EventLogWebEventProvider - Part 2

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
13 Apr 2010CPOL3 min read 8.4K   4  
In the first post of this series I've manage to find the correct eventId for each Web Event type, and by this time the major problem has been solved, but I cannot yet write a correct entry into the EventLog.I still have to decided the best severity type and category to apply.SeverityIf you

In the first post of this series I've manage to find the correct eventId for each Web Event type, and by this time the major problem has been solved, but I cannot yet write a correct entry into the EventLog.

I still have to decided the best severity type and category to apply.

Severity

If you look at entries in the EventLog generated by the default EventLogWebEventProvider you will find that they are marked mainly as Information and a few of them are also marked as Warning but no one is ever marked as Error.

Since I'm making my own provider I will take this chance to map the EventLog entry severity type according to the source Web Event.[more]

Web Event

EventLog entry Severity
WebBaseEventEventLogEntryType.Information
WebManagementEventEventLogEntryType.Information
WebApplicationLifetimeEventEventLogEntryType.Information
WebRequestEventEventLogEntryType.Information
WebHeartbeatEventEventLogEntryType.Information
WebBaseErrorEventEventLogEntryType.Warning
WebRequestErrorEventEventLogEntryType.Error
WebErrorEventEventLogEntryType.Error
WebAuditEventEventLogEntryType.Information
WebSuccessAuditEventEventLogEntryType.SuccessAudit
WebAuthenticationSuccessAuditEventEventLogEntryType.SuccessAudit
WebFailureAuditEventEventLogEntryType.FailureAudit
WebAuthenticationFailureAuditEventEventLogEntryType.FailureAudit
WebViewStateFailureAuditEventEventLogEntryType.FailureAudit

Naturally, you can decided to map the Web Events exactly has the default EventLogWebEventProvider does.

Finally all I need is to do is set the correct category for the Web Events.

Category

Although all Web Events belong to the same category 'Web Events', the problem is how to make the correct text appear.

The value shown in the category property is a resource string and to select the correct category value is necessary to set the  exact resourcekey.

That is not so hard to do, I could have made my own resource assembly with only one resource, but I have a better way ... I will use the same resource assembly that ASP.NET use.

To figure out which assembly to use I simply used regedit.exe to look at "HK_LM\System\CurrentControlSet\Services\EventLog\Application\ASP.NET 2.0.50727.0"

registry_EventLog

What I look for are the settings used by the "ASP.NET 2.0.50727.0" EventLog source which is the source used to write the Web Events EventLog entries.

The settings I will use are the CategoryCount and CategoryMessageFile keys because they are the ones that instruct which category assembly to load.

Name

Data
CategoryCount5
CategoryMessageFileC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_rc.dll

Please note that the CategoryMessageFile may change according to operating system and ASP.NET version.

Finally, I need to know the exact resourcekey of the "Web Event" string, and since there simply 5 resources in assembly it took no time to get the following table:

Category Resource Key

Category
0None
1Setup
2Uninstall
3Web Event
4File Monitoring
5Admin Service

Now I simply need to configure my EventLog source to use those same settings.

As I said in part 1, you can create an EventLog source using the EventLog.CreateEventSource method, but for setting the CategoryCount and CategoryMessageFile values you must use this specific overload EventLog.CreateEventSource(EventSourceCreationData sourceData).

That's it ... I've got everything I need and the final result look like this:

EventLog

It looks similar to the usual but if you look closer you will find the differences.

Benefits

What you need to keep in mind is that:

  • the EventId and Category values are keep unchanged;
  • the entry Type respects the Web Event type as opposing to the EventLogWebEventProvider given by ASP.NET that only uses Information and Warning;
  • the EventLog source can be one of my choise (not the usual "ASP.NET x.xxx") and can change by application;
  • you can choose either to use the existing EventLogs or to create a brand new one for your application(s) .

As a final note remember that with this provider you can now organize your application EventLog entries into specific EventLogs, and you may also filter them by application Source.

Download the code here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect everis
Portugal Portugal
Over 13 years of experience in the Software Development working mainly in the banking and insurance industry.

Over 3 year of experience as Operations Team Leader focused on Infrastructure Management and Software Configuration Management.

I've been honored with the Microsoft Most Valuable Professional (MVP) Award for three consecutive years, 2010, 2011 and 2012, in recognition to exceptional technical contributions and leadership.

Current / Recent Technical Projects
- Dominican Republic Instance management, including 2nd line System management, capacity management, SW monitoring and deploy management
- Colombian SECOPII Instance management, including 2nd line System management, capacity management, SW monitoring and deploy management
- Vortal Main Instance management, including 2nd line System management, capacity management, SW monitoring and deploy management
- Vortal Development ecosystem management, including Server management, , capacity management, SW monitoring and deploy management

Areas of Specialization:
- Operations Management - ISO 20000 & ISO 27001 driven
- Team Management and Coaching
- Technology Leadership, Solutions/Architecture
- Product life cycle management, Continuous Integration
- Technological background in Microsoft frameworks and tools.

Comments and Discussions

 
-- There are no messages in this forum --