Logging

27
Logging and why it’s the shit.

Transcript of Logging

Page 1: Logging

Loggingand why it’s the shit.

Page 2: Logging

You are going to love logging!

Page 3: Logging

Ever had to debug a live issue and had no information to go on?

Page 4: Logging

The aim of logging is to tell the story of what the application is doing

Page 5: Logging

You tell the story to ILog

Page 6: Logging

private static readonly ILog _log = LogManager.GetLogger(typeof(Foo));

Page 7: Logging

There are 4 different log levels

Page 8: Logging

Info

Page 9: Logging

High level user activity

Page 10: Logging

_log.InfoFormat( "User {0} has just logged in", user.Id);

Page 11: Logging

Debug

Page 12: Logging

Details of the internal logic of a method

Page 13: Logging

_log.DebugFormat( "User {0} needs to pay {2} bills", user.Id, user.Bills.Count);

Page 14: Logging

Warn

Page 15: Logging

Something suspicious has happened from which we have recovered but...

if this happens a lot, we need to investigate

Page 16: Logging

_log.WarnFormat( "User {0} tried to hack our servers", user.Id);

Page 17: Logging

Error

Page 18: Logging

Something went seriously wrong - this requires investigation because it means we have a bug.

Page 19: Logging

_log.ErrorFormat( "Could not find User {0}’s bills", user.Id);

Page 20: Logging

Where the hell are the logs aand how do we use them?

Page 21: Logging

tail -f is your friend

Page 22: Logging

Adding an identifier (e.g. user id) to your logs makes it easier to grep

Page 23: Logging

Some do’s & don’ts

Page 24: Logging

DO create a logger in every class you use

Page 25: Logging

DON’T be afraid of doing LOTS of

logging

Page 26: Logging

Questions?

Page 27: Logging

Thanks to

Ed Devlin (Who initially came up with these guidelines)David Padbury (Who I stole these slides from)

Images Good Friends by Juliana Coutinho, http://www.flickr.com/photos/ngmmemuda/4166182931/Four Colors by by Tambako the Jaguar http://www.flickr.com/photos/tambako/2390708966/Engineering Information by Calistobreeze http://www.flickr.com/photos/callisto/2172555529/Swat by fengschwing http://www.flickr.com/photos/fengschwing/4931950933/Comments and faves by bumblesweet http://www.flickr.com/photos/bumblesweet/4253655700/Ahhhhhhh by kennymatic http://www.flickr.com/photos/kwl/4678498113/in/set-72157623544311963/What is going on? by SAN_DRINO, http://www.flickr.com/photos/san_drino/1454922072/The Simple Life by kennymatic http://www.flickr.com/photos/kwl/4574642827/in/set-72157623544311963/the_dos_and_donts_with_babies_001 by DrJohnBullas http://www.flickr.com/photos/johnbullas/2247403198/What the wut? by kennymatic http://www.flickr.com/photos/kwl/4514986410/in/set-72157623544311963/