liveBook · Manning

Chapter 26: Monitoring and troubleshooting errors with logging

What you will learn in chapter 26 of ASP.NET Core in Action, 3e

This introduction explains why production logging matters and previews ASP.NET Core’s logging abstractions, providers, filtering, and structured logging features.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction explains why production logging matters and previews ASP.NET Core’s logging abstractions, providers, filtering, and structured logging features.

Key terms: logging, informational messages, warnings, errors, generic logging interface, ASP.NET Core logging framework, dependency injection, ILogger, logging providers, verbosity

26.1 Using logging effectively in a production app

This section explains why production logging is essential for diagnosing problems, auditing behavior, and tracing the events that lead to errors.

Key terms: logging, auditing, analytics, breadcrumb trail, errors, nonerror events, production, error, context, breadcrumb logging

26.1.1 Highlighting problems using custom log messages

This section contrasts ASP.NET Core’s built-in infrastructure logs with targeted custom messages that make application problems and important events easier to diagnose.

Key terms: infrastructure logging, ASP.NET Core Framework libraries, EF Core, Razor Page, page handler, custom log message, RecipeId, parameters, variables

26.1.2 The ASP.NET Core logging abstractions

This section explains how ASP.NET Core’s logging interfaces connect application log calls to one or more configurable output providers.

Key terms: ILogger, ILoggerProvider, ILoggerFactory, Log(), CreateLogger(), WebApplicationBuilder, console logger

26.2 Adding log messages to your application

This section introduces creating application log messages through injected ILogger and explains the common information carried by each log record.

Key terms: ILogger<T>, ILogger, ILoggerFactory, ILoggerProvider, LogInformation, dependency injection, LogLevel, log level, category, message

26.2.1 Log level: How important is the log message?

This section explains how to assign ILogger log levels to convey a message’s severity and use those levels to control useful logging in development and production.

Key terms: ILogger, log level, Critical, Error, Warning, Information, Debug, Trace, LogInformation, LogWarning

26.2.2 Log category: Which component created the log?

This section explains how log categories identify the component that created a log entry and how to create categorized ILogger instances.

Key terms: category, ILogger, log level, filtering, ILogger<T>, ILoggerFactory, CreateLogger(), fully qualified name, RecipeController, RecipeService

26.2.3 Formatting messages and capturing parameter values

This section explains how message templates and parameter values create searchable structured log data instead of only formatted text.

Key terms: placeholders, format string, parameters, key-value pair, RecipeCount, structured logging, semantic logging, key-value pairs, JSON, UserId

26.3 Controlling where logs are written using logging providers

This section explains how logging providers route ILogger messages to multiple destinations and how to add a third-party rolling file provider or choose centralized production logging.

Key terms: ILogger, ILoggerProvider, logging provider, WebApplicationBuilder.Logging, NuGet package, AddFile(), ClearProviders(), console provider, debug provider, rolling file provider

26.4 Changing log verbosity with filtering

This section explains how ASP.NET Core logging filters reduce production log noise by selecting one most-specific rule based on provider, category, and log level.

Key terms: log level, log category, logging provider, filtering rule, Default, Microsoft namespace, provider-specific rule, category prefix, global minimum level, LogLevel:Default

26.5 Structured logging: Creating searchable, useful logs

This section introduces structured logging as a way to store log properties as searchable key-value pairs and previews using Seq and scopes to analyze them effectively.

Key terms: structured logging, unstructured text, key-value pairs, JSON, query, filter, analytics, EventLevel, recipe ID, logging provider

26.5.1 Adding a structured logging provider to your app

This section shows how to send ASP.NET Core structured logs to Seq and use their captured properties to investigate production errors.

Key terms: Seq, structured logging provider, AddSeq(), logging provider, structured logging, message format string, captured parameter, key-value pair, RecipeCount, filtering

26.5.2 Using scopes to add properties to your logs

This section explains how logging scopes attach shared contextual data to every log message within a group of operations, especially as searchable structured properties.

Key terms: logging scopes, ILogger.BeginScope<T>(), scope state, using block, Dictionary<string, object>, Seq, structured logging properties, Scope property, ToString()

26.6 Summary

This summary recaps how to configure, write, filter, store, and structure ASP.NET Core logs for diagnosing production problems.

Where this is used later

Concepts explained in this chapter

← Chapter 25: Authentication and authorization for APIs Chapter 27: Publishing and deploying your application →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.