17 Monitoring and troubleshooting errors with logging

 

This chapter covers

  • Understanding the components of a log message
  • Writing logs to multiple output locations
  • Controlling log verbosity in different environments using filtering
  • Using structured logging to make logs searchable

Logging is one of those topics that seems unnecessary, right up until the point when you desperately need it! There’s nothing more frustrating than finding an issue that you can only reproduce in production, and then discovering there are no logs to help you debug it.

Logging is the process of recording events or activities in an app and often involves writing a record to a console, a file, the Windows Event Log, or some other system. You can record anything in a log message, though there are generally two different types of message:

  • Informational messages—A standard event occurred: a user logged in, a product was placed in a shopping cart, or a new post was created on a blogging app.
  • Warnings and errors—An error or unexpected condition occurred: a user had a negative total in the shopping cart, or an exception occurred.

Historically, a common problem with logging in larger applications was that each library and framework would generate logs in a slightly different format, if at all. When an error occurred in your app and you were trying to diagnose it, this inconsistency made it harder to connect the dots in your app to get the full picture and understand the problem.

17.1  Using logging effectively in a production app

 
 
 

17.1.1 Highlighting problems using custom log messages

 
 
 
 

17.1.2 The ASP.NET Core logging abstractions

 
 
 
 

17.2  Adding log messages to your application

 
 
 

17.2.1 Log level: how important is the log message?

 
 
 
 

17.2.2 Log category: which component created the log

 
 
 

17.2.3 Formatting messages and capturing parameter values

 
 

17.3  Controlling where logs are written using logging providers

 
 
 

17.3.1 Adding a new logging provider to your application

 
 

17.3.2 Replacing the default ILoggerFactory with Serilog

 
 

17.4  Changing log verbosity with filtering

 
 
 

17.5  Structured logging: creating searchable, useful logs

 
 
 
 

17.5.1 Adding a structured logging provider to your app

 
 
 
 

17.5.2 Using scopes to add additional properties to your logs

 
 

17.6  Summary

 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest