Modern syslog client for .NET with dual logging (local libc + remote UDP) and RFC 5424 support. Fork of jitbit/SyslogCore with critical improvements.
// 1. One-time initialization
cSyslogClient.Init(appName: "MyApp",remoteServer: "10.0.0.1" // Optional);
// 2. Logging (auto module detection)
cSyslogClient.Write("Payment processed", SyslogLevel.Info);
// 3. Graceful shutdown
cSyslogClient.Shutdown();-
Dual logging: Local (libc) + Remote (UDP RFC 5424)
-
Structured messages: Timestamps, hostnames, priority levels
-
Auto caller detection: [CallerMemberName] integration
-
Resource-safe: Proper GCHandle and UdpClient disposal
-
Zero dependencies: Single C# file (~150 LOC)
The original library was limited to local syslog. We added:
🚀 Remote syslog server support
📡 RFC 5424 compliance
🛡️ Safer resource management
🔍 Automatic caller module tracking
ASP.NET Core Integration
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
cSyslogClient.Init("WebApp", "192.168.113.100");
app.Lifetime.ApplicationStopping.Register(() =>
{
cSyslogClient.Write("Shutting down...");
cSyslogClient.Shutdown();
});
app.MapGet("/", () => {
cSyslogClient.Write("Homepage visited"); // Auto-detects "[GET] /" as module
return "Hello World";
});cSyslogClient.Init(
appName: "Backend",
remoteServer: "10.0.0.1", // UDP target
remotePort: 8514, // Custom port
customHostName: "server-1" // Override hostname
);2025-06-25T13:31:41.190245+03:00 dev69-u lk[206841]: [INFO] main: startup v0.2.1.0
2025-06-25T13:50:40.203339+03:00 dev69-u be[207439]: [INFO] main: startup v2.0.0.0
2025-06-25T13:57:50.985781+03:00 dev69-u be[207439]: [INFO] main(): shutdown
2025-06-25T13:57:51.513765+03:00 dev69-u be[207668]: [INFO] main: startup v2.0.0.0
2025-06-25T13:58:16.690086+03:00 dev69-u lk[206841]: [INFO] lk-files: Test from filesController
2025-06-25T13:58:23.113230+03:00 dev69-u be[207668]: [INFO] GetFileName: File report.pdf uploaded to caller
To direct logs to a dedicated file instead of /var/log/syslog, use Linux's local facilities (local0 through local7). Example for local0:
Create rsyslog config (/etc/rsyslog.d/20-myapp.conf):
# Logs with facility=local0 to /var/log/myapp.log
local0.* /var/log/myapp.log
& stop # Prevent duplicate loggingThis code uses Local0 by default. You can change it in:
// In LibC.openlog() call:
LibC.openlog(..., facility: 16 << 3); // 16=local0, 17=local1, etc.For high-throughput scenarios:
-
Consider batching UDP messages
-
Future upgrade path to LibraryImport (AOT support)
-
Async logging possible via _udpClient.SendAsync