in

Foo Theory

Partners in Community - serving up some ice cold Kool-Aid!
Welcome to footheory.com.  The bloggers and contributing members on this site are consultants, project/program managers and software architects working across the US.  Our community will focus on Microsoft technologies, .NET architecture, software patterns & practices and just plain stream of consciousness.

this.Reflect(); - Donn's Weblog

The technology Blog of Donn Felker

Creating .NET Event Sources with PowerShell

I use Enterprise Library for Logging and I use different event sources for each app. I've noticed that creating event sources is kind of a pain sometimes. Either you have to write an app that does it for you, or you have to write some logic in your code that checks for the event source. Either way, I think that's too bloated for in-house software. Now for software that has to be deployed, then ok, no problem I see the use. But we're talking bout non-released code here. Code that is used on an internal site or externally facing site.

Or you can use PowerShell, simple as pie. :)

This one liner will check for the Event Source and if it does not exist, it will create it for you. Real easy. Gotta love PowerShell.

 

if (![System.Diagnostics.EventLog]::SourceExists("MySourceName")) { [System.Diagnostics.EventLog]::CreateEventSource("MySourceName", "Application") }

Now if we write an event to the event log, it will show up because the source now exists. :)

You HAVE TO love one liners that can replace entire applications. :) Albeit, not a big app, but an app, none the less.

Published Feb 25 2008, 01:42 PM by donnfelker
Filed under:

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add
Copyright ASIQS Corporation © 2006, All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems