Added custom token support

This commit is contained in:
2026-01-30 21:23:39 +01:00
parent f54d40b092
commit 9c77e61ec9
6 changed files with 172 additions and 28 deletions

View File

@@ -296,6 +296,39 @@ Dutch Passport Numbers (9 alphanumeric characters
Dutch Identification Document Numbers (varying formats)
Custom keywords specified in LoggerSettings
Header tokens:
{date} {time} {ts} {tz} {unix} {ticks}{newline}
{sev} {category} {env}{newline}
{host} {machine}{newline}
{process} {pid} {procstart} {uptime}{newline}
{thread} {threadname} {task}{newline}
{user}{newline}
{app} {appbase} {domain}{newline}
{framework} {os} {arch}{newline}
{mem} {gc}{newline}
{cwd}
Example of custom header:
```csharp
[Date: 2026-01-30] [Time: 14:22:11.384] [2026-01-30 14:22:11.384] [UTC] [Unix: 1738246931] [Ticks: 638422525313840000]
[Severity: Info] [Category: Startup] [Env: Production]
[Host: api-01] [Machine: API-SERVER-01]
[Process: MyService] [PID: 4216] [ProcStart: 2026-01-30T14:20:03.5123456Z] [Uptime: 128s]
[Thread: 9] [ThreadName: worker-1] [TaskId: 42]
[User: svc-api]
[App: MyService.exe] [AppBase: C:\apps\myservice\] [Domain: 1]
[Runtime: .NET 8.0.1] [OS: Linux 6.6.9] [Arch: X64]
[Memory: 128MB] [GC: 12/4/1]
[CWD: /app]
```
Add Custom tokens:
```csharp
Logger.LoggerSettings.HeaderTokens.AddCustomToken("spaceShuttleId", context => $"[Shuttle: {context.SpaceShuttleId}]");
```
**Code for enabling GrayLog in the above *advanced* logger class:**