ILogEventSink interface defines the contract for log event destinations in Serilog. Implementing this interface allows you to create custom sinks that write log events to any destination, such as files, databases, cloud services, or external systems.
Interface Definition
Methods
Emit
Emits the provided log event to the sink.The log event to write. Contains all information about the log entry including timestamp, level, message template, properties, and exception data.
Remarks
Implementers should allow exceptions to propagate when event emission fails. The logger will handle exceptions and produce diagnostics appropriately.Implementation Guidance
When implementingILogEventSink, consider the following:
Exception Handling
Allow exceptions to bubble up rather than catching them internally. Serilog’s pipeline will handle failures appropriately and can emit self-log diagnostics.Thread Safety
Ensure your implementation is thread-safe, asEmit() may be called concurrently from multiple threads:
Performance Considerations
- Keep
Emit()fast to avoid blocking the logging pipeline - Consider batching for high-volume scenarios (see
IBatchedLogEventSink) - Avoid synchronous I/O operations when possible
- Use buffering for network or disk-based sinks
Disposal
If your sink holds resources, implementIDisposable:
Example Implementation
Related Interfaces
IBatchedLogEventSink- For sinks that process events in batches for better performanceILogEventFilter- For filtering which events reach the sinkILogEventEnricher- For adding properties before events reach the sink