File logging format changed from standard text to CMTrace-compatible format.
2025-01-10 16:33:18.123 +01:00 [INF] SecureBootWatcher Client Starting
2025-01-10 16:33:18.124 +01:00 [INF] Version: 1.1.1.48182
2025-01-10 16:33:19.500 +01:00 [ERR] Failed to connect to Azure Queue
<![LOG[SecureBootWatcher Client Starting]LOG]!><time="16:33:18.123+01:00" date="01-10-2025" component="SecureBootWatcher.Client" context="" type="1" thread="1" file="">
<![LOG[Version: 1.1.1.48182]LOG]!><time="16:33:18.124+01:00" date="01-10-2025" component="SecureBootWatcher.Client" context="" type="1" thread="1" file="">
<![LOG[Failed to connect to Azure Queue]LOG]!><time="16:33:19.500+01:00" date="01-10-2025" component="SecureBootWatcher.Client" context="" type="3" thread="1" file="">
Console output remains unchanged (human-readable).
? Industry Standard - Used by SCCM/Intune administrators worldwide
? Better Troubleshooting - Color-coded errors, warnings, info
? Advanced Filtering - Filter by component, thread, log level
? Real-Time Monitoring - Watch logs as client runs
? Integration Ready - Works with SCCM, Splunk, Azure Monitor
Added:
// CMTrace-compatible log format
var cmTraceOutputTemplate = "<![LOG[{Message:lj}{NewLine}{Exception}]LOG]!>" +
"<time=\"{Timestamp:HH:mm:ss.fff}{Timestamp:zzz}\" " +
"date=\"{Timestamp:MM-dd-yyyy}\" " +
"component=\"SecureBootWatcher.Client\" " +
"context=\"\" " +
"type=\"{Level:w}\" " +
"thread=\"{ThreadId}\" " +
"file=\"\">";
Log.Logger = new LoggerConfiguration()
// ...existing config...
.Enrich.WithThreadId() // NEW: Thread tracking
.WriteTo.File(
path: logPath,
rollingInterval: RollingInterval.Day,
retainedFileCountLimit: 30,
outputTemplate: cmTraceOutputTemplate) // NEW: CMTrace format
.CreateLogger();Added NuGet package:
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />Option 1: From SCCM installation
C:\Program Files (x86)\Microsoft Endpoint Manager\AdminConsole\bin\CMTrace.exe
Option 2: Download Microsoft System Center Configuration Manager Toolkit
Option 3: Use OneTrace (newer version)
C:\Program Files (x86)\Microsoft Endpoint Manager\AdminConsole\bin\OneTrace.exe
# Open latest log file
$latestLog = Get-ChildItem "C:\Program Files\SecureBootWatcher\logs" -Filter "client-*.log" |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1
& "CMTrace.exe" $latestLog.FullNameIn CMTrace:
- Tools ? Start Monitoring
- Logs update automatically as client writes new entries
Show only errors:
- View ? Show only Errors
Highlight keywords:
- Tools ? Highlight ? Add
- Enter:
Certificate,API,Error, etc.
| Scenario | Log Path |
|---|---|
| Scheduled Task (SYSTEM) | C:\Program Files\SecureBootWatcher\logs\client-YYYYMMDD.log |
| Manual Run (User) | {ExeDirectory}\logs\client-YYYYMMDD.log |
| Today's Log | client-20250110.log |
| Level | CMTrace Type | Color |
|---|---|---|
| Information | 1 | White/Gray |
| Warning | 2 | Yellow |
| Error | 3 | Red |
- Existing
appsettings.jsonfiles work without changes - Log level controlled by
Logging:LogLevelsection (unchanged) - No new parameters or settings required
- Console output unchanged (still human-readable)
- Log file location unchanged
- Log retention unchanged (30 days)
- File naming unchanged (
client-YYYYMMDD.log)
Before deploying:
# 1. Restore packages (new: Serilog.Enrichers.Thread)
cd SecureBootWatcher.Client
dotnet restore
# 2. Rebuild client
dotnet clean
dotnet build -c Release
# 3. Verify new format in logs
.\bin\Release\net48\SecureBootWatcher.Client.exe
# 4. Check log output
Get-Content ".\bin\Release\net48\logs\client-*.log" -Tail 5Expected output:
<![LOG[SecureBootWatcher Client Starting]LOG]!><time="16:33:18.123+01:00" date="01-10-2025" ...
After rebuild, redeploy using existing method:
- Intune Win32 app
- SCCM package
- GPO deployment
- Manual copy
No configuration changes needed on target devices.
- Rebuild client with new Serilog.Enrichers.Thread package
- Run client manually and verify logs generated
- Open log file with CMTrace - verify format recognized
- Check errors show in red, warnings in yellow
- Test real-time monitoring (Tools ? Start Monitoring)
- Verify console output still human-readable
- Test on pilot device before mass deployment
Solution:
dotnet restore
dotnet buildSymptom: Logs show as plain text, no color coding
Solution:
- Verify log file contains CMTrace format:
Get-Content "logs\client-*.log" -First 5
- Expected: Should start with
<![LOG[ - If not, rebuild client from updated source
Cause: Encoding mismatch
Solution: CMTrace expects UTF-8. Serilog uses UTF-8 by default. No action needed.
# Open today's log with CMTrace
$log = Get-ChildItem "C:\Program Files\SecureBootWatcher\logs" |
Where-Object { $_.Name -like "client-$(Get-Date -Format 'yyyyMMdd').log" }
& "CMTrace.exe" $log.FullName
# View last 20 entries (PowerShell alternative)
Get-Content "C:\Program Files\SecureBootWatcher\logs\client-*.log" -Tail 20
# Search for errors in all logs
Get-ChildItem "C:\Program Files\SecureBootWatcher\logs" -Filter "client-*.log" |
ForEach-Object {
Select-String -Path $_.FullName -Pattern 'type="3"'
}
# Count errors per log file
Get-ChildItem "C:\Program Files\SecureBootWatcher\logs" -Filter "client-*.log" |
ForEach-Object {
$errors = (Select-String -Path $_.FullName -Pattern 'type="3"').Count
[PSCustomObject]@{
File = $_.Name
Errors = $errors
}
}- Rebuild Client with new logging format
- Test on Pilot Devices (5-10 devices)
- Collect Feedback from IT team on log readability
- Deploy to Production via Intune/SCCM
- Train IT Team on using CMTrace
- Full Documentation:
docs\CMTRACE_LOGGING_GUIDE.md - CMTrace Download: Microsoft System Center Configuration Manager Toolkit
- Alternative: OneTrace (newer Microsoft tool)
- Log Analytics Integration: Configure Azure Monitor Agent for custom logs
Change Summary:
- ? File logging now uses CMTrace format
- ? Console output unchanged (human-readable)
- ? No configuration changes required
- ? Rebuild + redeploy needed
- ? Works with SCCM, Intune, monitoring tools
Impact: Low (cosmetic change to log format)
Risk: None (console output unchanged, logs still readable)
Benefit: Better troubleshooting with CMTrace viewer