7 Application logging

 

This chapter covers

  • Application logging origin and purposes
  • Logging techniques using the ILogger interface
  • Differences between unstructured and structured logging
  • Implementing an alternative logging framework with Serilog

The term logging, when used in an IT context, defines the process of keeping track of all the events occurring within the application (and their context information) in a structured, semistructured, and/or unstructured format, and outputting them to a dedicated view and/or storage channel. Such a channel is often called secondary to distinguish it from the primary output mechanism the software uses to communicate with the end user: the user interface (UI).

The primary purpose of logging is to keep track of the various interactions between the software and its users: state changes, access to internal resources, event handlers that trigger in response to user actions, exceptions thrown by internal modules, and so on. Because this activity monitoring task is performed while the application is running, each log entry is typically shown (or recorded) with a timestamp value representing the moment when the logged event occurred.

In this chapter, after a brief overview of the concept and importance of logging, we’ll learn how to create a structured logging mechanism for our web API project by using the ILogger interface, as well as some third-party components that implement it.

7.1 Application logging overview

7.1.1 From boats to computers

7.1.2 Why do we need logs?

7.2 ASP.NET logging

7.2.1 A quick logging test

7.2.2 Log levels

7.2.3 Logging configuration

7.2.4 Logging providers

7.2.5 Event IDs and templates

7.2.6 Exception logging

7.3 Unstructured vs. structured logging

7.3.1 Unstructured logging pros and cons

7.3.2 Structured logging advantages