Search

Categories

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Send mail to the author(s) E-mail

# Thursday, 10 September 2015

Passing 0 Parameters to a function and logging

// Logging using a decorator - passing 0 parameters to // Action is like a function which can take parameters but doesn't return anything. // Passing in 2 method group QuoteImporter, Log // Passing in 2 lambda expression (anonymous function) () => QuoteImporter, s => Log(s) // Passing in 2 anonymous methods delegate() { QuoteImporter(); }, delegate(string s) {Log(s);}; Action run = () => QuoteImporterLogger(QuoteImporter, Log); run(); } public static void QuoteImporterLogger(Action quoteImporter, Action<string> log) { log("Start QuoteImporter"); quoteImporter(); log("End QuoteImporter"); } // Don't want logging code cluttering up public static void QuoteImporter() { Console.WriteLine("In QuoteImporter"); } public static void Log(string message) { Console.WriteLine($"log: {message}"); }

Passing 1 Parameter to a function and logging

// Logging using a decorator - passing in 1 parameter private static void Main() { // Function - given a string, return a string. // s and t represent the inbound parameters into ParseLine and Log (not needed) // line is inbound parameter into ParseLineLogger Func<string, string> run = line => ParseLineLogger(s => ParseLine(s), t => Log(t), line); string result = run("blah"); } public static string ParseLineLogger(Func<string, string> parseLine, Action<string> log, string line) { Console.WriteLine($"Start ParseLine with line: {line}"); string result = parseLine(line); Console.WriteLine($"Result: {result}"); Console.WriteLine("End ParseLine"); return result; } public static string ParseLine(string line) { return line + " ok"; } public static void Log(string message) { Console.WriteLine($"log: {message}"); }
| | # 
# Tuesday, 16 December 2014
( Logging | NDC )

http://michelebusta.com/

She is passionate about logging!

Why Log?

  • Troubleshoot
  • Visibility in real time
  • Security Audits
  • Review early detection of problems

What?

image
Screenshots copyright MichelleB

  • Application events eg exceptions
  • Audit eg login attemps
  • Activity eg user feature usage

Make it easy – implement a log helper for all developers eg ILogger
Debug, Info, Warn, Error, Thrown

image

  • Elmah
  • NLog
  • Log4Net

image

Put in a switch to turn off logging if all goes wrong

http://loader.io/ – stress test app

Elastic search!
Lucene

Kibana for visualisation
Logstash
Splunk

Summary

  • Something manageable
  • Evolve
  • Reduce io not put logs into SQL
  • Real time analytics for troubleshooting
| | #