Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
450
|
Chapter 8: Diagnostics
Solution
Use the event log built into the Microsoft Windows operating system to record spe-
cific events that occur infrequently. The
AppEvents class shown in Example 8-3 con-
tains all the methods needed to create and use an event log in your application.
Example 8-3. Creating and using an event log
using System;
using System.Diagnostics;
public class AppEvents
{
// Constructors
public AppEvents(string logName) :
this(logName, Process.GetCurrentProcess( ).ProcessName, ".") {}
public AppEvents(string logName, string source) : this(logName, source, ".") {}
public AppEvents(string logName, string source, string machineName)
{
this.logName = logName;
this.source = source;
this.machineName = machineName;
if (!EventLog.SourceExists(source, machineName))
{
EventSourceCreationData sourceData =
new EventSourceCreationData(source, logName);
sourceData.MachineName = machineName;
EventLog.CreateEventSource(sourceData);
}
log = new EventLog(logName, machineName, source);
log.EnableRaisingEvents = true;
}
// Fields
private EventLog log = null;
private string source = "";
private string logName = "";
private string machineName = ".";
// Properties
public string Name
{
get{return (logName);}
}
public string SourceName
This is the Title of the Book, eMatter Edition
Copyright ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
C# Cookbook

C# Cookbook

Joe Mayo
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata