Log Reader Service
Overview
ILogReaderService reads the log files the application has written to disk and streams them back as LogMessage items. The default LogReaderService enumerates the *.logs files in the configured folder and deserializes the JSON entries they contain.
These files are produced by the file logging provider (RegisterLogToFile), which writes structured JSON entries into rolling yyyy-MM-dd_N.logs files. The reader is the other half of that pair: it reads from the same folder and expects the same format. The built-in Log Viewer page uses this service as its data source.
The order of the returned messages is not guaranteed — sort them on the consuming side if you need a strict chronology.
Usage
Enumerate the messages with await foreach; pass a CancellationToken to stop a long enumeration early:
Registration
The service is part of the core services and by default reads from the standard log folder:
The folder is taken from the LogViewer configuration section (LogReaderOptions) and resolved relative to the application data folder; it defaults to logs. To override it in code, pass a configure delegate:
In a design-time environment the registration is skipped entirely; DesignTime.LogReaderService provides NullLogReaderService.Instance, which returns no messages.
API
ILogReaderService
Reads saved log files and streams their entries.
Method | Return Type | Description |
|---|---|---|
|
| Reads all |
ILogReaderService.LoadItemsFromLogFile
Parameter | Type | Description |
|---|---|---|
|
| A token that cancels the enumeration. |
LogMessage
Represents a single log entry.
Property | Type | Description |
|---|---|---|
|
| Time the entry was written. |
|
| Severity level. |
|
| Logger category the entry belongs to. |
|
| Log message text. |
|
| Optional additional details. |