Logging Using Microsoft Event Logging using Microsoft Event

  • Slides: 9
Download presentation
Logging Using Microsoft Event Logging, using Microsoft Event Log 1

Logging Using Microsoft Event Logging, using Microsoft Event Log 1

Introduction • Ships must keep a written log telling speed, direction, destination, etc. •

Introduction • Ships must keep a written log telling speed, direction, destination, etc. • A kind of diary of the ship. • Large programs should keep a written log telling about all the major events in the “life” of the program. • Facebook produces 25 TB log file per day (2009)! • 25 TB = 25 000 0000 bytes • Server programs usually keeps a log telling which clients requested what service from the server – and when – and how the server responded to the request • Ordinary response • Exception(al) response Logging, using Microsoft Event Log 2

Usages of logging • Monitoring a running system • Does it perform well, or

Usages of logging • Monitoring a running system • Does it perform well, or does it need more resources. • Debugging • Application does not work. Maybe the log can tell us why. • Comparable to the ”black box” on an airplane • Statistics • Example Web. Shop: • • • When do customers arrive? For how long do they shop? How large a percentage of customers actually buy something? Can the users find the intended way through the shop? Etc… Logging, using Microsoft Event Log 3

Microsoft Event Logging framework • Name space: System. Diagnostics • Class: Event. Log •

Microsoft Event Logging framework • Name space: System. Diagnostics • Class: Event. Log • The class Event. Log can be used in 2 ways 1. Calling static methods 2. Make an object and call ordinary methods • Example: Event. Log. Example Logging, using Microsoft Event Log 4

Viewing the log entries • The log entries can be viewed in Windows •

Viewing the log entries • The log entries can be viewed in Windows • “Show log files” • Shows all log entries from all application running on your computer • That is a lot! • Focus on “Application” and maybe add a “Filter” • Filtering on “Event Source” is most efficient Logging, using Microsoft Event Log 5

Configuring a logger if (!Event. Log. Source. Exists(Source)) { Event. Log. Create. Event. Source(Source,

Configuring a logger if (!Event. Log. Source. Exists(Source)) { Event. Log. Create. Event. Source(Source, s. Log); } • Example: Event. Log. Example • Problem • If you want to create an event logger with a new source you get Security. Exception …. • You can only create new event loggers when you run as Administrator • Solution • Run Visual Studio as Administrator • Will run your application as Administrator Logging, using Microsoft Event Log 6

Logging levels • Logging can be done at several levels of importance. • Viewing

Logging levels • Logging can be done at several levels of importance. • Viewing the log you can filter out less important messages • Enumeration: Event. Log. Entry. Type (next slide) Logging, using Microsoft Event Log 7

Enumeration: Event. Log. Entry. Type Ordinary levels Audit levels • Information • Low level.

Enumeration: Event. Log. Entry. Type Ordinary levels Audit levels • Information • Low level. Default level. • Significant, successful operation • Warning • Middle level • Conditions that may cause future problems • Success. Audit • Example: Login success • Failure. Audit • Example: Login fail • Wrong username + password • Error • High level • Significant problem. Usually means loss of data or functionality. Logging, using Microsoft Event Log 8

References and further readings • Microsoft Support: How to write to an event log

References and further readings • Microsoft Support: How to write to an event log using Visual C# • http: //support. microsoft. com/kb/307024 • MSDN Event. Log class • http: //msdn. microsoft. com/enus/library/system. diagnostics. eventlog(v=vs. 110). aspx Logging, using Microsoft Event Log 9