What is Instrumentation ?
It is a process which deals with logging and measuring all the things happening at application level.
Logging Events
There are some situations where a developer cannot predict if anything is going to fail in the application may be at developer end or a customer end. A developer must track such events through some mechanisms to ensure the smooth execution of an application. In order to do this .Net framework provides System.Diagnostics namespace to log events and debug application.
There are 3 default types of event logs as;
Creating an Event log:
EventLog objEventLog = new EventLog("MyApplication");
objEventLog.Source="MyApplication";
objEventLog.WriteEntry("EventLog has been created", EventLogEntryType.Information);
Event sources are registered with windows registry. Hence to write into the event log fully trusted code is required. Partially or no trusted code can cause potential harm to the application as well as user's system .
Deleting an EventLog:
EventLog provides Delete method which removes all the logged events.
EventLog.Delete("MyApplication");
Reading entries from an EventLog:
EventLog stores each event in the form of an entry. EventLogEntry object represents single entry from an EventLog. Below is the code to demonstrate how to read EventLog;
EventLog objEventLog = new EventLog("MyApplication");
objEventLog.Source="MyApplication";
foreach (EventLogEntry objEventLogEntry in objEventLog.entries)
{
console.WriteLine(objEventLogEntry.Source);
}
It is a process which deals with logging and measuring all the things happening at application level.
Logging Events
There are some situations where a developer cannot predict if anything is going to fail in the application may be at developer end or a customer end. A developer must track such events through some mechanisms to ensure the smooth execution of an application. In order to do this .Net framework provides System.Diagnostics namespace to log events and debug application.
There are 3 default types of event logs as;
- Application
- Security
- System
Creating an Event log:
EventLog objEventLog = new EventLog("MyApplication");
objEventLog.Source="MyApplication";
objEventLog.WriteEntry("EventLog has been created", EventLogEntryType.Information);
Event sources are registered with windows registry. Hence to write into the event log fully trusted code is required. Partially or no trusted code can cause potential harm to the application as well as user's system .
Deleting an EventLog:
EventLog provides Delete method which removes all the logged events.
EventLog.Delete("MyApplication");
Reading entries from an EventLog:
EventLog stores each event in the form of an entry. EventLogEntry object represents single entry from an EventLog. Below is the code to demonstrate how to read EventLog;
EventLog objEventLog = new EventLog("MyApplication");
objEventLog.Source="MyApplication";
foreach (EventLogEntry objEventLogEntry in objEventLog.entries)
{
console.WriteLine(objEventLogEntry.Source);
}
No comments:
Post a Comment