Overview
The Intent.AspNetCore.Logging.Serilog module adds structured logging capabilities to your ASP.NET Core application using Serilog, a popular .NET logging library. Unlike traditional text-based logging, Serilog captures log events as structured data, making logs queryable, filterable, and far more useful for diagnosing issues in production environments.What is Serilog?
Serilog is a diagnostic logging library for .NET applications that:- Captures structured data instead of plain text
- Supports multiple sinks (Console, File, Graylog, Application Insights, etc.)
- Enriches log events with contextual information
- Provides powerful filtering and configuration options
- Integrates seamlessly with ASP.NET Core
What Gets Generated
Serilog Configuration
Startup configuration that wires up Serilog with selected sinks and enrichers:Program.cs
Bounded Logging Destructuring Policy
A custom destructuring policy that prevents excessive logging by:- Limiting collection sizes
- Truncating objects with too many properties
- Replacing problematic types (streams, byte arrays) with placeholders
- Handling exceptions during property access
Infrastructure/Logging/BoundedLoggingDestructuringPolicy.cs
Configuration Settings
Additional configuration inappsettings.json:
appsettings.json
Installation
Prerequisites
- An ASP.NET Core application in Intent Architect
Installation Steps
Install the module
In Intent Architect, right-click on your application and select Manage Modules. Search for
Intent.AspNetCore.Logging.Serilog and install it.Configure sinks
In Application Settings, navigate to Serilog and select which sinks to include (Console, File, Graylog, Application Insights).
Run the Software Factory
Execute the Software Factory to generate the Serilog configuration and destructuring policy.
Configuration
Sinks
The module supports multiple logging destinations:Console
Writes logs to the console with colored output for different log levels.
File
Writes logs to rolling files with daily rotation (e.g.,
log-20260307.txt).Graylog
Sends structured logs to Graylog for centralized log management.
Application Insights
Integrates with Azure Application Insights for cloud-based log analytics.
- Open Application Settings in Intent Architect
- Navigate to Serilog Settings
- Select the sinks you want to enable
- Run the Software Factory
Log Levels
Configure log levels inappsettings.json:
appsettings.json
Environment-Specific Configuration
Create environment-specific settings:appsettings.Development.json
appsettings.Production.json
Usage Examples
Basic Logging
Enriching with Context
using block will include UserId and CorrelationId properties.
Performance-Sensitive Logging
Use log level checks to avoid expensive operations:Exception Logging
- The exception type, message, and stack trace
- Structured properties (
OrderId,Amount) - The format specifier (
:Cfor currency formatting)
Serilog vs OpenTelemetry
Understanding when to use each:| Feature | Serilog | OpenTelemetry |
|---|---|---|
| Primary Focus | Application log events (structured text) | Traces, metrics, and logs |
| Use Case | Detailed application logging | Distributed system observability |
| Data Format | Log events with properties | Spans, metrics, log records |
| Best For | Application diagnostics, auditing | Performance monitoring, distributed tracing |
| Integration | Easy .NET integration | Cross-platform, vendor-neutral |
Use both for a complete observability stack: Serilog for detailed application logs and OpenTelemetry for distributed tracing and metrics.
Best Practices
Use Structured Logging
Always use message templates with properties, not string interpolation:
Log at Appropriate Levels
- Verbose/Debug: Developer diagnostics
- Information: General application flow
- Warning: Unexpected but handled situations
- Error: Failures requiring attention
- Fatal: Critical system failures
Avoid Sensitive Data
Never log passwords, tokens, or personally identifiable information (PII).
Use Scoped Context
Add contextual properties with
LogContext.PushProperty() for related operations.Bounded Destructuring Policy
The generatedBoundedLoggingDestructuringPolicy prevents:
- Runaway memory from logging large collections
- Performance issues from serializing complex object graphs
- Log noise from excessive property logging
Integration with Other Modules
OpenTelemetry
Serilog logs are automatically included in traces when OpenTelemetry logging is enabled.
ASP.NET Core
Serilog integrates with the ASP.NET Core logging pipeline and middleware.
Entity Framework Core
Log SQL queries and database operations with appropriate log levels.
Azure Application Insights
Send structured logs to Application Insights for powerful querying with KQL.
Troubleshooting
Logs Not Appearing
Check log level configuration: Ensure the minimum log level allows your log statements:File Sink Not Writing
Verify file path and permissions:logs directory exists or Serilog has permission to create it.
Too Much Logging
Suppress noisy namespaces:Related Resources
Next Steps
OpenTelemetry
Add distributed tracing and metrics
Application Insights
Send logs to Azure for analysis
Health Checks
Monitor application health
