Logging and tracing Using Microsoft Tracing API A very brief introduction Logging and tracing1
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 25TB log file per day (2009)! 25TB = 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 and tracing2
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 WebShop: 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 and tracing3
Microsoft Tracing framework Name space: System.Diagnostics Main class: Trace Trace.WriteLine(“something happened in the life of the application”); Example: PersonTrace Trace.AutoFlush = true; Flush at every Write(…) and WriteLine(…) Logging and tracing4
Trace listener You can add several listeners to a Trace Trace.Listeners.Add(another listener) Listeners can use different media: Screen (aka. Console) File, etc. Listeners can use different formats Ordinary text XML You can even make your own listener by extending the abstract class TraceListener Example: PersonTrace -> MySmsTraceListener Logging and tracing5
Design pattern: Observable The Trace framework uses the Observable design pattern. The various listeners are said to observe the Trace class (Observable) The Observable class can have 0-many Observers Observers can be addede / removed at runtime Everytime something happens to the Observable all the Observers are notified (a method is called) Logging and tracing6