For many years, logs have been an essential part of troubleshooting application and infrastructure performance. They help provide visibility into how our applications are running on each of the various infrastructure components. Log data contains information such as out of memory exception or hard disk errors.
See the Microsoft Enterprise Library. It includes the Logging Application Block and that documentation might be what you are looking for. You can see the MSDN Documentation without having to install the library first. Specifically, see Key Scenarios and Design of the Logging Application Block to answer your question (maybe even if you are not using .NET).
UPDATE (April 23, 2013) See Embracing Semantic Logging using the new Semantic Logging Application Block
A good article is written on this at Effective logging practices ease enterprise development.
The crux is:
Some tips :
If you really want to dive into philosophy on the subject, try "Do Not Believe in Structured Logging" on Miloslav Trmač's blog.
"...these lessons were learned the hard way..."
There are tons of logging frameworks out there including log4net and log4j, but the right one for you will depend on your platform and system.
The best logging techniques will depend largely on your platform and the design of your system. You need to know/decide how much information you need to diagnose a particular type of problem. Generally, you should instrument your code in a way that does not require a lot of code repetition or modification. Logging frameworks in .NET that use Attributed classes and methods are a good example of low-impact instrumentation. You should also be able to modify the level of logging (Low through Verbose) through configuration without having to shut down or restart any services.
Serilog is another structured logging solution that has become popular since the question was first asked.
In his interview, Mr. Blumhardt talks about building the library as a result of going through the pain of logging that we have all experienced. They talk on the show about simple logging during initial development and formalizing logging as the project matures. Good stuff and may add to the best practices knowledge base brought up in the question.
From the website:
Like other logging libraries for .NET, Serilog provides diagnostic logging to files, the console, and so-on. It is easy to set up, has a clean API, and is portable between recent .NET platforms.
Unlike other logging libraries for .NET, Serilog is built with structured log data in mind. Parameters passed along with log messages are not destructively rendered into a text format. Instead, they're preserved as structured data that can be written in document form to a NoSQL data store
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With