log : Debug Logging Helper
On this page
Summary
Output debug messages to the trace log during template processing. Useful for debugging data binding and template logic. Does not render any visible content in the PDF.
Based on: <log> element for trace logging
Syntax
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
message(s) |
String/Expression | Yes | One or more strings or expressions to log (concatenated) |
level |
String | No | Log level: debug, info, warn, error (default: info) |
category |
String | No | Category for filtering log messages (optional) |
Log Levels
| Level | Description | Use Case |
|---|---|---|
debug |
Verbose debugging | Detailed tracing during development |
info |
Informational | General information (default) |
warn |
Warning | Potential issues that don’t stop execution |
error |
Error | Significant problems worth noting |
Examples
Basic Logging
Logging Values
Data:
doc.Params["model"] = new {
user = new {
name = "John Doe",
id = 12345
}
};
Log Output:
User: John Doe (ID: 12345)
With Log Level
With Category for Filtering
Logging in Loops
Data:
doc.Params["model"] = new {
orders = new[] {
new { orderNumber = "12345", total = 1250.00m },
new { orderNumber = "12346", total = 45.99m },
new { orderNumber = "12347", total = 2100.00m }
}
};
Log Output:
Processing order #12345
High-value order: $1250
Processing order #12346
Processing order #12347
High-value order: $2100
Logging with Expressions
Conditional Debugging
Underlying Implementation
The `` helper compiles to:
<log data-message=""
data-level="Verbose|Message|Warning|Error"
data-category="category name" />
The log entry is written to the document’s trace log during databinding and does not produce any visible output in the PDF.
Notes
- Does not render any visible content in the PDF
- Messages are written to the document’s trace log
- Multiple values are automatically concatenated with spaces
- Supports expressions (function calls, property access, etc.)
- Unknown parameters are silently ignored
- Use
doc.AppendTraceLog = trueto enable logging in C# - View log output in CollectorTraceLog for unit testing
- Category helps filter log messages for specific features
- Log level affects visibility based on trace log configuration
- Useful for debugging complex conditional logic and iterations
Enabling Trace Logging
To see log output, enable trace logging in your document:
doc.AppendTraceLog = true;
doc.SaveAsPDF(output);
// Access log entries
var collector = doc.TraceLog as CollectorTraceLog;
foreach (var entry in collector)
{
Console.WriteLine($"[{entry.Level}] {entry.Category}: {entry.Message}");
}