Wednesday, September 07, 2005

Event Logging in .Net

Kevin McNeish always said, "What's easy in VFP is difficult in .Net and what's difficult in .Net is easy in VFP". I've found a perfect example of this...writing to the Windows Event Log. I have an Event Log session that I've presented at several conferences and will do it again in November in Germany. It takes the entire session to show how to write to and read from the log in VFP. Well, in .Net, it's a couple of lines of code. Yep...that's it.

using System.Diagnostics;

if (!EventLog.SourceExisists("MyApp")
EventLog.CreateEventSource("MyApp", "Application");
EventLog.WriteEntry("MyApp", "An event occurred");

That's it. There are some optional parameters for the WriteEntry method where you can specify the event type and an event number. Oh that it were this easy with VFP.

Comments: Post a Comment



Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]