---
source: https://iinventedlight.com/library/notes/dotnet-logging.md
title: "Logging with ILogger in .NET"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC BY 4.0 (dotnet/docs); prose restates or closely paraphrases cited source lines"
license_family: dotnet-docs-ccby
rule_check: "needs rule check (family not in auto-publish rule; check.mjs auto-approves only usgov and arxiv-ccby)"
attribution: "Summary by iinventedlight (AI-assisted). Sources: Microsoft Learn (.NET docs), Logging in C# - .NET, CC BY 4.0 (dotnet/docs); Microsoft Learn (.NET docs), Logging providers - .NET, CC BY 4.0 (dotnet/docs)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: .NET"
tags: ['dotnet', 'logging', 'observability']
sources:
  - id: S1
    title: "Logging in C# - .NET"
    publisher: Microsoft Learn (.NET docs)
    url: https://learn.microsoft.com/en-us/dotnet/core/extensions/logging
    accessed: 2026-11-04
    license: "CC BY 4.0 (dotnet/docs)"
  - id: S2
    title: "Logging providers - .NET"
    publisher: Microsoft Learn (.NET docs)
    url: https://learn.microsoft.com/en-us/dotnet/core/extensions/logging-providers
    accessed: 2026-11-04
    license: "CC BY 4.0 (dotnet/docs)"
---
# Logging with ILogger in .NET

**Answer:** .NET supports high performance, structured logging via the ILogger API to help monitor application behavior and diagnose issues. Configure different logging providers to write logs to different destinations. (S1)

## Setup

- Basic logging providers are built-in, and many third-party providers are available. (S1)
- The ILoggerFactory stores all the configuration that determines where log messages are sent. (S1)

## Providers

- Logging providers persist logs, except for the Console provider, which only displays logs as standard output. (S2)
- The Azure Application Insights provider stores logs in Azure Application Insights. (S2)
- To override the default set of logging providers added by Host.CreateApplicationBuilder, call ClearProviders and add the logging providers you want. (S2)
- To configure a service that depends on ILogger<T>, use constructor injection or provide a factory method. (S2)

## Claims
- id: C1
  claim: ILogger gives structured logging.
  source: S1
  evidence: "structured logging via the ILogger API to help monitor application behavior and diagnose issues."
- id: C2
  claim: ILoggerFactory holds routing configuration.
  source: S1
  evidence: "The ILoggerFactory stores all the configuration that determines where log messages are sent."
- id: C3
  claim: Console only displays logs.
  source: S2
  evidence: "except for the Console provider, which only displays logs as standard output."
- id: C4
  claim: ClearProviders overrides the defaults.
  source: S2
  evidence: "call ClearProviders and add the logging providers you want."

## Sources
- [S1] Logging in C# - .NET. Microsoft Learn (.NET docs). https://learn.microsoft.com/en-us/dotnet/core/extensions/logging . License: CC BY 4.0 (dotnet/docs). Accessed 2026-11-04.
- [S2] Logging providers - .NET. Microsoft Learn (.NET docs). https://learn.microsoft.com/en-us/dotnet/core/extensions/logging-providers . License: CC BY 4.0 (dotnet/docs). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
