Skip to content

Latest commit

 

History

History
47 lines (31 loc) · 2.22 KB

File metadata and controls

47 lines (31 loc) · 2.22 KB

OpenUrzednik.Extensions.Logging

🇵🇱 Wersja polska (skrócona)

⚠️ Unofficial: OpenUrzednik.NET is a community project. It is not affiliated with, authorized or endorsed by Narodowy Bank Polski (NBP) or any other Polish public institution.

Adapter that sends the logs of OpenUrzednik.NET clients to ILogger from Microsoft.Extensions.Logging.

Part of OpenUrzednik.NET. See the main README for an overview of the project.

Installation

dotnet add package OpenUrzednik.Extensions.Logging

Usage

using OpenUrzednik.Extensions.Logging;
using OpenUrzednik.Nbp;

var client = new NbpGoldPriceClient(httpClient,
    logger: loggerFactory.CreateOpenUrzednikLogger<NbpGoldPriceClient>());

The log category is the client's full type name (e.g. OpenUrzednik.Nbp.NbpGoldPriceClient), as with ILogger<T>. You can turn a whole provider's logs on or off by prefix:

{
  "Logging": {
    "LogLevel": {
      "OpenUrzednik.Nbp": "Debug"
    }
  }
}

If you already have an ILogger, use new OpenUrzednikLogger(logger).

Every entry has an event id (EventId with an id and a name, e.g. 1001 RequestTimedOut), fixed by the library and the same in every client of a provider; NBP lists them in NbpLogEvents and the telemetry reference. Filter by event id rather than message text, which may change.

Entries are structured: they carry named values (e.g. provider, path) and the template in {OriginalFormat}, like entries from LoggerMessage. Serilog, OpenTelemetry and other providers see them as separate properties. The message text is formatted with the invariant culture.

Dependencies

The package depends on Microsoft.Extensions.Logging.Abstractions. The core and provider packages have their own logging interfaces and don't need this dependency (ADR-0003).