logging
TRANSCRIPT
Loggingand why it’s the shit.
You are going to love logging!
Ever had to debug a live issue and had no information to go on?
The aim of logging is to tell the story of what the application is doing
You tell the story to ILog
private static readonly ILog _log = LogManager.GetLogger(typeof(Foo));
There are 4 different log levels
Info
High level user activity
_log.InfoFormat( "User {0} has just logged in", user.Id);
Debug
Details of the internal logic of a method
_log.DebugFormat( "User {0} needs to pay {2} bills", user.Id, user.Bills.Count);
Warn
Something suspicious has happened from which we have recovered but...
if this happens a lot, we need to investigate
_log.WarnFormat( "User {0} tried to hack our servers", user.Id);
Error
Something went seriously wrong - this requires investigation because it means we have a bug.
_log.ErrorFormat( "Could not find User {0}’s bills", user.Id);
Where the hell are the logs aand how do we use them?
tail -f is your friend
Adding an identifier (e.g. user id) to your logs makes it easier to grep
Some do’s & don’ts
DO create a logger in every class you use
DON’T be afraid of doing LOTS of
logging
Questions?
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/