Click here to Skip to main content
Click here to Skip to main content

Event Log RSS Feed Generator

By , 30 Jun 2005
 

Introduction

How many times did you need to check the Event Log of your production web server but since you do not have permission to log on to that server, you had to wait for the administrator or webmaster to be available and open the Event Viewer for you?

In my experience, that happens very often. Often enough to let me think twice before writing code that logs messages to the Event Log. Unfortunately (or fortunately), the Event Log is still a very reliable place to log diagnostic messages, and even if we log to a custom database infrastructure, there's the chance that that database becomes unavailable and we need a fallback plan. The Event Log is usually a good last resort place to log important messages. Aside of that, many other applications and services already log their errors and warnings in the Event Log, so we will always be coming back to it at a point or another.

What is desirable here is a more flexible way to access the Event Log. More flexible but not less safe. We also need to protect our system messages from prying eyes.

Enter the RSS Feed Generator

With this goal in mind, I wrote a very simple utility to produce RSS feeds from the Event Logs in any system that has IIS with ASP.NET 1.x installed.

The utility is comprised of a single ASP.NET webform without code behind. This single .aspx file accepts querystring parameters that enables you to better specify how many and what kind of messages you are interested in.

Using the code

To get this utility going, all you need to do is unzip the accompanying .zip file and place the files GetLog.aspx and rssToTable.xsl in any existing or new ASP.NET application virtual folder. After the files are there, you'll have access to the RSS XML just by browsing to it, like:

http://yourserver/thefolder/GetLog.aspx

If your browser is XSLT-capable (like IE), the produced XML will be formatted in HTML automatically to help you find the information you are looking for.

The above URL will return, by default, the last 25 entries in the Application Event Log. You can change the number of returned entries using the top parameter, like:

http://yourserver/thefolder/GetLog.aspx?top=40

You can change the desired event log using the log parameter, like:

http://yourserver/thefolder/GetLog.aspx?log=YourLog

Note: The System and Security logs are programmatically blocked to prevent access to critical information.

You can filter on specific types of messages using the types parameter, like:

http://yourserver/thefolder/GetLog.aspx?GetLog.aspx?types=error,warning

As you can see, this parameter is a comma delimited list of event log message types. The available types are Information, Warning, Error, SuccessAudit, and FailureAudit, but you are likely to be more interested in the first three types.

You can restrict the desired message source using the source parameter, like:

http://yourserver/thefolder/GetLog.aspx?source=MSSQLSERVER

To get even more interesting filtering, you can combine any of the above parameters to get closer to messages you are watching for:

http://yourserver/thefolder/GetLog.aspx?GetLog.aspx?
   top=40&types=error&log=MyLog&source=MyApplication

Security Notes

Event Log messages often contain precious information that should not fall in the wrong hands. When you deploy this utility in any of your servers, be careful not to make it accessible by those who shouldn't be reading these messages.

Configure the ASP.NET application folder that contains the file to not be accessible without proper authentication, or to only be accessible through an internal IP address or some other scheme that protects your messages.

RSS Feed Aggregators

This utility combined with a decent RSS aggregator of your liking can provide you a collection of subscribed feeds that will allow you to keep an eye on your applications and search for diagnostic messages when some error occurs.

History

  • June 27th 2005 - Following suggestions in the comments, changed the GUID format and the HTTP error code returned in case of a forbidden query. Added an XSLT transformation to the raw output, to make the display prettier in the browser.
  • May 25th 2005 - Code submitted.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Sergio Pereira
United States United States
Member
Sergio Pereira is a senior software developer and architect. He currently makes his services available throughout Chicago and suburbs. Sergio has always made himself proficient in mainstream Microsoft technologies and has a deep interest in emerging technologies and the software life cycle aspect of development.
Feel free to contact Sergio at sergio_pereira(AT)msn(dot)com.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralIE7 ignoring the XSLmemberGlennDanko21 Feb '07 - 11:25 
By default, IE7 renders feeds with its own brand of formatting. The .XSL is completely ignored.
 
I like your XSL format better.
 
Now, I know I can go to Internet Options --> Content Tab --> Feed Settings and uncheck "Turn on feed reading view". This makes it appear as intended.
 
But I'd like to turn this off programmatically via my page (ASP.NET pages using C# code behind and javascript). That way, if my user wanted this "feature", they'd still be able to get all their other feeds formated by IE7.
 
Is this possible?
AnswerRe: IE7 ignoring the XSLmemberSergio Pereira21 Feb '07 - 12:26 
GlennDanko wrote:
The .XSL is completely ignored.

 
I know, it really sucks.... especially if you have long, pre-formatted lines of text, which fall behind the retarded top-left navigation controls.
 
GlennDanko wrote:
I'd like to turn this off programmatically via my page

 
I don't think it is possible. It's a browser-specific feature, not part of the browser DOM, much less Javascript itself. If we could at least disable the formatting for specific URLs, then I could live with it. Right now I simply disable the feature.
 


 
_______________________
Sergio Pereira

GeneralRe: IE7 ignoring the XSL [modified]memberGlennDanko22 Feb '07 - 8:46 
Exactly, the text was getting cut off.
 
By the way, I kept messing around and I think I tricked IE into not formatting it. In the ASPX, I changed
wr.WriteStartElement"("rss");
to be
wr.WriteStartElement"("MyOwnTag");
 
Then, in the XLS, I changed the XLS template from "rss" to be "MyOwnTag" (being careful to match capitalization).
 
I guess now, IE doesn't see it as RSS and decides not to take over. It works even when the "feature" is turned on.
 

-- modified at 15:16 Thursday 22nd February, 2007
Edit: Forgot to say, thanks for posting this little app. It's exactly what I'm looking for!
GeneralRe: IE7 ignoring the XSLmemberjcp19 May '08 - 5:04 
I found that changing the GetItemText() method in the aspx file to add a <div> tag seems to format the text a lot better in IE7 and allows you to still use IE7 as an RSS feed reader. You do loose the table at the top but at least you can view just the new items added since you last refreshed it.
 
From:   "<pre>{7}<pre>";
 
To:      "<pre><div style="\"width:98%;" border:="" 1px="" solid="" black;="" \="">{7}</div></pre>"; </pre></pre></div>
GeneralOkay got it working, now have a quick questonmembermarkhooper217 Jan '07 - 8:52 
Okay looks like the problem was with the virtural server, so i got the rest of it working now.
 
Now here is a queston, saw you want to view logs of different servers in the enviroment, is there a way other then having IIS running on all servers to get the logs from them?
 

AnswerRe: Okay got it working, now have a quick questonmemberSergio Pereira17 Jan '07 - 12:26 
You'll just need to change the code a little bit.
The line that looks like:
EventLog log = new EventLog(LogName);
Needs to have an extra argument - the computer name
EventLog log = new EventLog(LogName, "remote-machine-name");
 
As long as the User-Id that runs the asp.net application has rights to access the other computer's event log, then it'll work. Maybe you should change the virtual directory authentication to Integrated Authentication (disabling anonymous access) over the domain where the computers are.. then you'll need to configure your rss client with the user/password to access the feed.
 

 
_______________________
Sergio Pereira

GeneralCant get it to workmembermarkhooper216 Jan '07 - 9:38 
All i get is page cannot be displayed, when navagating to http://aspdev/rssfeed/GetLog.aspx, I can veiw anything else but cant get this to run at all, just wondering if there is somthing that i am missing here
 

Also i am NOT familir with ASP, this was a queston asked of me that i have been researching and was just testing out this solution
 
thanks
 

GeneralRe: Cant get it to workmemberSergio Pereira16 Jan '07 - 10:57 
markhooper2 wrote:
Also i am NOT familir with ASP,

 
My suggestion is that your get just a little familiar with it. Look up on google how to create a new virtual application directory in IIS and drop the files in there. It's that simple. You can even go straight to the IIS management console and go right-clicking to create a new virtual directory. Just make sure it is also an application and not just a directory.

 
_______________________
Sergio Pereira

GeneralI get errormemberarash_7 Feb '06 - 22:31 
when i run your example i get the following error.
Could you explain what do you mean with Logname = "Application".
 
Error:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
 

----------------------------------------------------------------------------
 
Only one top level element is allowed in an XML document. Error processing resource 'http://localhost:1416/GetMyLog/GetLog....
 
IGNITO/Application/1119<h4>The following event...

GeneralRe: I get errormemberSergio Pereira8 Feb '06 - 2:35 

arash_ wrote:
Could you explain what do you mean with Logname = "Application".

 

In case you're not familiar with the Windows system event log, it has more than one log (it normally installs with at least three logs: Application, System, and Security.) The most general of these logs is the Application log, which the code here defaults to if you don't pass any parameters specifying otherwise. You can create your own logs and message sources if you need.
Regarding your error, make sure you have all the needed files in the same folder (the .aspx, and the .xsl)
 
arash_ wrote:
Only one top level element is allowed in an XML document.

 

Did you do anything to the .aspx code, like trying to change it somehow? Your error message aludes to a problem in the XML format, which I have never seen with this tool (and I use it extensively, in a whole lot of servers in my network).
 
_______________________
Sergio Pereira

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 1 Jul 2005
Article Copyright 2005 by Sergio Pereira
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid