Creating .NET Event Sources with PowerShell

by Donn Felker 25. February 2008 12:42

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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

PowerShell

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Donn Felker

Senior Consultant
MCTS
ScrumMaster
Agile Practitioner

About Me | Books I Recommend

Gotta Pay The Bills


Tag cloud

    Popular Posts

    RecentComments

    Comment RSS

    Calendar

    <<  January 2009  >>
    MoTuWeThFrSaSu
    2930311234
    567891011
    12131415161718
    19202122232425
    2627282930311
    2345678

    View posts in large calendar