Centralized application log monitoring is essential for developers, DevOps teams, SREs, and technical founders who want to quickly locate issues, reduce noise, and gain actionable insights from their logs. Serilog sink plays a crucial role in forwarding structured logs from .NET applications to centralized log management platforms like LogInformant. But beyond basic integration, extending the Serilog sink to enrich logs with custom contextual data can dramatically improve your troubleshooting speed and alert accuracy.
This article dives into practical ways to extend Serilog sink for custom log enrichment, helping your team get more from centralized log management, advanced log search, and AI log analysis capabilities. If you’re shipping backend services or managing distributed systems, these techniques will help you build richer logs that tell a clearer story when incidents happen.
Why Extend Serilog Sink for Custom Log Enrichment?
Out-of-the-box, Serilog sink forwards logs with standard properties like timestamp, level, message, and exception details. However, real-world applications often benefit from additional context that isn’t captured automatically:
- User or session identifiers to correlate logs with specific users or transactions
- Service or environment metadata to distinguish logs from multiple microservices or deployment stages
- Custom error codes or business metrics to prioritize alerts and triage faster
- Correlation IDs for tracing distributed requests across services
Adding this custom data directly in the Serilog sink ensures that logs arriving at your centralized log management system are already enriched, reducing the need for complex post-processing or guesswork during incident response.
Practical Approaches to Custom Log Enrichment in Serilog Sink
1. Use Enrichers in Serilog Configuration
Serilog supports enrichers — modular components that add properties to every log event. You can write custom enrichers to inject any contextual information your application generates.
Example: Adding a custom enricher for user ID and environment
public class UserIdEnricher : ILogEventEnricher
{
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var userId = GetCurrentUserId(); // Implement your user ID retrieval logic
if (!string.IsNullOrEmpty(userId))
{
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("UserId", userId));
}
}
}
Register the enricher during Serilog setup:
Log.Logger = new LoggerConfiguration()
.Enrich.With<UserIdEnricher>()
.Enrich.WithProperty("Environment", "Production")
.WriteTo.LogInformantSink() // Hypothetical sink method
.CreateLogger();
This approach ensures every log event includes UserId and Environment properties, searchable and filterable in centralized log management.
2. Implement Custom Sink Wrappers for Dynamic Data
If your custom data changes per request or context, consider wrapping or extending the Serilog sink to inject dynamic properties at write time.
Example: A sink wrapper that adds correlation IDs from HTTP headers
public class CorrelationIdSink : ILogEventSink
{
private readonly ILogEventSink _innerSink;
public CorrelationIdSink(ILogEventSink innerSink)
{
_innerSink = innerSink;
}
public void Emit(LogEvent logEvent)
{
var correlationId = GetCorrelationIdFromContext(); // Your retrieval logic
if (!string.IsNullOrEmpty(correlationId))
{
logEvent.AddPropertyIfAbsent(new LogEventProperty("CorrelationId", new ScalarValue(correlationId)));
}
_innerSink.Emit(logEvent);
}
}
You can chain this sink wrapper with the LogInformant Serilog sink to enrich logs before forwarding.
3. Leverage LogInformant’s Integration for Structured Logs
LogInformant supports structured logging ingestion via Serilog sink, preserving enriched properties for advanced log search and AI log analysis. Ensure your custom properties are included in the structured log payload so LogInformant can index and alert on them.
For example, enriched properties like UserId, CorrelationId, or Environment can be used to create targeted log alerting rules or dashboards that highlight issues affecting specific users or environments.
Checklist: Extending Serilog Sink for Custom Log Enrichment
- Identify key contextual data to add (user IDs, environment, correlation IDs, custom metrics)
- Implement or configure Serilog enrichers to add static or global properties
- Create custom sink wrappers if dynamic, request-scoped data is needed
- Validate that enriched properties appear in LogInformant logs and are searchable
- Build alerting rules in LogInformant based on enriched properties to reduce noise and prioritize incidents
- Use enriched logs in dashboards to visualize issues by user, service, or environment
- Monitor log volume and optimize enrichment to avoid excessive log size or noise
Next Steps with LogInformant
LogInformant offers centralized application log monitoring with advanced log search, log alerting software, dashboards, and AI log analysis. Its Serilog sink integration preserves your custom log enrichment, enabling faster troubleshooting and smarter incident response.
Explore the Serilog sink documentation to get started with integration and enrichment. For practical onboarding, visit the getting started guide to set up your free account and begin centralized log management quickly. Remember, a card verification is required before free-tier ingestion starts, so you can start with practical value right away.
By enriching your logs at the source with Serilog sink extensions, your team gains clearer insights, better alerting precision, and faster root-cause analysis powered by LogInformant’s AI-assisted investigation.
Ready to simplify your log monitoring and accelerate incident resolution? Visit LogInformant and start centralizing your application logs today.