liveBook · Manning

Unstructured logging

As explained in Building Web APIs with ASP.NET Core

Unstructured logging is the recording of application events as sequential free-form text without a fixed schema for fields or records.

Unstructured logging records application events as sequential free-form text rather than fields organized by a fixed schema. It is easy to view in a console or text editor, making recent entries convenient to inspect. section 7.2.6 section 7.3.1

Use unstructured logs with these practical expectations:

  • Review recent failures quickly when their approximate time is known. section 7.3.1
  • Search older or uncertain events with text tools such as Notepad Find or Linux grep. section 7.3.1
  • Expect large, verbose files to become difficult to browse and query. section 7.3.1
  • Add event IDs to exception entries when later filtering may matter, then consider structured providers or log-management tools. section 7.2.6 section 7.3.1

Logging an unhandled API exception

A Minimal API error endpoint can call app.Logger.LogError with an exception and the message "An unhandled exception occurred." Adding a custom Error_Get event ID makes related entries easier to identify, even though the output remains primarily text-oriented.

using MyBGList.Constants;
 
// ... nonrelevant code omitted
 
app.Logger.LogError(
CustomLogEvents.Error_Get,  #1
    exceptionHandler?.Error,
    "An unhandled exception occurred.");

Browse the event-ID LogError listing to see how an exception record receives a named numeric identifier. section 7.2.6

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Defines accessibility and retrieval trade-offs, demonstrates exception logging, and stops short of structured querying implementation.
Examples
Uses console and text-editor review, Notepad Find, Linux grep, verbose log files, and a Minimal API exception endpoint.
What it assumes
Assumes basic application-event logging and introduces ILogger-based exception recording before comparing storage approaches.
What you can do after
Diagnose recent API failures through sequential text records and text search, while recognizing when structured storage is needed.
How it connects
Connects unstructured logging with ILogger, event IDs, structured logging, logging providers, DBMS storage, and log-management tools.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.