ServiceStack.Logging is a collection of logging integration providers that adapt external .NET logging frameworks to ServiceStack's core logging abstractions (ILogFactory and ILog).
It enables ServiceStack applications to route internal framework logs and application diagnostic messages to their preferred logging destination:
- Serilog (
ServiceStack.Logging.Serilog): Structured logging adapter forwarding to Serilog sink pipelines. - NLog (
ServiceStack.Logging.NLog): Adapter for NLog targets and layout renderers. - Log4Net (
ServiceStack.Logging.Log4Net): Adapter for Apache log4net repositories. - Slack (
ServiceStack.Logging.Slack): Webhook logger publishing error notifications directly to Slack channels. - EventLog (
ServiceStack.Logging.EventLog): Windows Event Log integration. - ELMAH (
ServiceStack.Logging.Elmah): Intercepting logger signaling errors into ELMAH pipelines.
Target frameworks: net472;net6.0;net8.0;net10.0 (varying per provider package)
ServiceStack.Interfaces (ILogFactory, ILog, LogManager)
│
▼
ServiceStack.Logging
│
┌────────────┬───────┴────┬───────────┬────────────┐
▼ ▼ ▼ ▼ ▼
Serilog NLog Log4Net Slack EventLog
- Depends on:
ServiceStack.Interfaces, external logging SDKs (Serilog,NLog,log4net, etc.). - Depended on by: ServiceStack applications requiring external log aggregation and monitoring.
- Registration: Initialized early in application startup (before
AppHost.Init()) by settingLogManager.LogFactory.
| Package | Factory Class | Description |
|---|---|---|
ServiceStack.Logging.Serilog |
SerilogFactory |
Routes messages to Serilog Log.ForContext. |
ServiceStack.Logging.NLog |
NLogFactory |
Wraps NLog LogManager.GetLogger. |
ServiceStack.Logging.Log4Net |
Log4NetFactory |
Wraps Apache log4net repositories. |
ServiceStack.Logging.Slack |
SlackLogFactory |
Dispatches errors to Slack incoming webhooks. |
ServiceStack.Logging.EventLog |
EventLogFactory |
Writes to Windows Event Log sources. |
ServiceStack.Logging.Elmah |
ElmahInterceptingLogger |
Dispatches errors to ELMAH error signals. |
Setting LogManager.LogFactory = new SerilogFactory() transparently redirects all ServiceStack framework logging across the entire process without modifying service code.
Logging adapters wrap external framework dispatches in defensive try/catch blocks so failures in logging destinations (e.g., Slack webhook downtime, ELMAH configuration issues) never crash the calling application or suppress secondary loggers.
Sourced from
SECURITY_CHANGES.md. Follow these precautions:
- URLs pointing to
http://hooks.slack.commust be automatically upgraded tohttps://to prevent plaintext transmission of secret webhook tokens over the wire. - Fire-and-forget webhook tasks must observe faults via
.ContinueWith(..., TaskContinuationOptions.OnlyOnFaulted)to prevent unobserved task exceptions. - Limit inner exception traversal to a fixed depth (e.g. 20) to prevent infinite loops on circular exceptions.
EventLoginstances must be wrapped inusingblocks to prevent unmanaged handle leaks.- Windows Event Log entry text must be truncated to 31,839 characters to avoid buffer overflow
ArgumentExceptioncrashes. - Guard source verification calls against
SecurityExceptionon unprivileged accounts.
- In
SerilogFactory.GetLogger(string typeName), fall back toForContext("SourceContext", typeName)whenType.GetType(typeName)returns null. Handle null message payloads gracefully.
- Use
Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly()to avoidArgumentNullExceptionin web/worker hosts whereGetEntryAssembly()is null.
-
Configuring a Logging Provider at Startup
LogManager.LogFactory = new SerilogFactory();
-
Creating a Custom Log Provider
- Implement
ILogFactoryandILog. - Ensure
ILog.Errormethods safely handle null messages and null exceptions.
- Implement