-
Notifications
You must be signed in to change notification settings - Fork 0
logging
Peterson Fernandes edited this page Aug 19, 2026
·
1 revision
CHDSharp is silent by default. It integrates with Microsoft.Extensions.Logging so you can route internal diagnostics to any compatible provider.
Set the static Chd.LoggerFactory before performing library operations:
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Extensions.Logging;
var serilogLogger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console()
.CreateLogger();
Chd.LoggerFactory = new SerilogLoggerFactory(serilogLogger);
// All subsequent Chd/ChdFile operations log through Serilog
var result = Chd.CheckFile(File.OpenRead("game.chd"), "game.chd", deepCheck: true);Any ILoggerFactory-compatible provider works:
-
Serilog (
Serilog.Extensions.Logging) -
NLog (
NLog.Extensions.Logging) Microsoft.Extensions.Logging.Console- your own
ILoggerFactoryimplementation
| Area | Level | Examples |
|---|---|---|
| Verification | Information / Debug | progress percentages, array-pool statistics, compression-type statistics per CHD |
| Metadata | Debug | tag + length + ASCII payload of every metadata entry |
| Errors | Warning / Error | failed metadata reads, precache failures, decompression exceptions (with the inner exception and hunk number) |
| Per-codec | Debug | block summaries, repeated-block counts |
Because every log call is a pre-compiled LoggerMessage.Define delegate, the overhead is negligible when logging is disabled.
To disable logging again (e.g. in tests):
Chd.LoggerFactory = null;Chd.LoggerFactory = new SerilogLoggerFactory(
new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.File("chdsharp.log", rollingInterval: RollingInterval.Day)
.CreateLogger());-
LoggerFactoryis read lazily per operation, so you can swap providers at runtime; for predictable behavior, set it once at startup. - The logging package (
Microsoft.Extensions.Logging.Abstractions) is the library's only non-Zstd dependency and is marked optional in the sense that the library functions perfectly with it never set.
CHDSharp
Format & internals
API & usage
Operations
Writing CHDs
Reference