SyslogLogging 2.0.9
See the version list below for details.
dotnet add package SyslogLogging --version 2.0.9
NuGet\Install-Package SyslogLogging -Version 2.0.9
<PackageReference Include="SyslogLogging" Version="2.0.9" />
<PackageVersion Include="SyslogLogging" Version="2.0.9" />
<PackageReference Include="SyslogLogging" />
paket add SyslogLogging --version 2.0.9
#r "nuget: SyslogLogging, 2.0.9"
#:package SyslogLogging@2.0.9
#addin nuget:?package=SyslogLogging&version=2.0.9
#tool nuget:?package=SyslogLogging&version=2.0.9
SyslogLogging
๐ Modern, high-performance C# logging library for syslog, console, and file destinations with async support, structured logging, background queuing, and Microsoft.Extensions.Logging integration.
Targeted to .NET Standard 2.0+, .NET Framework 4.6.2+, .NET 6.0+, and .NET 8.0.
โจ What's New in v2.0.9+
๐ฅ Major New Features
- ๐ช๏ธ Full async support with
CancellationToken
throughout - ๐ Structured logging with properties, correlation IDs, and JSON serialization
- ๐ Microsoft.Extensions.Logging integration (ILogger, DI support)
- โก Background message queuing with batching for I/O optimization
- ๐พ Persistent queues that survive application restarts
- ๐๏ธ Enterprise-grade thread safety with comprehensive race condition prevention
- ๐ฏ Integrated SyslogServer for end-to-end testing
- ๐ก๏ธ Comprehensive input validation on all public properties
- ๐งช Extensive thread safety testing (20+ specialized concurrent scenarios)
๐ง Performance & Reliability
- >100K messages/second throughput in background mode
- <1ms latency for queue operations
- Memory pressure handling with configurable limits
- Automatic batch processing for optimal I/O
- Zero message loss with persistent file-backed queues
๐ Quick Start
Simple Logging
using SyslogLogging;
LoggingModule log = new LoggingModule();
await log.InfoAsync("Hello, world!");
Async with Structured Data
using SyslogLogging;
LoggingModule log = new LoggingModule("mysyslogserver", 514);
// Simple async logging
await log.ErrorAsync("Something went wrong", cancellationToken);
// Structured logging with properties
LogEntry entry = new LogEntry(Severity.Warning, "Rate limit exceeded")
.WithProperty("RequestsPerSecond", 150)
.WithProperty("ClientId", "user123")
.WithCorrelationId(Request.Headers["X-Correlation-ID"]);
await log.LogEntryAsync(entry);
Fluent Structured Logging
log.BeginStructuredLog(Severity.Info, "User login")
.WithProperty("UserId", userId)
.WithProperty("IpAddress", ipAddress)
.WithProperty("Timestamp", DateTime.UtcNow)
.WithCorrelationId(correlationId)
.WriteAsync();
High-Performance Background Processing
LoggingModule log = new LoggingModule("logserver", 514);
log.Settings.EnableBackgroundQueue = true;
log.Settings.BatchSize = 100; // Process 100 messages at once
log.Settings.FlushInterval = 5000; // Flush every 5 seconds
// Fire-and-forget logging - messages are queued and processed in background
log.Info("High-throughput message 1");
log.Info("High-throughput message 2");
// ... thousands more messages
๐ Microsoft.Extensions.Logging Integration
ASP.NET Core / Generic Host
// Program.cs or Startup.cs
services.AddLogging(builder =>
{
builder.AddSyslog("syslogserver", 514, configure: module =>
{
module.Settings.EnableBackgroundQueue = true;
module.Settings.BatchSize = 50;
});
});
// In your controllers/services
public class MyController : ControllerBase
{
private readonly ILogger<MyController> _logger;
public MyController(ILogger<MyController> logger)
{
_logger = logger;
}
public IActionResult Get()
{
_logger.LogInformation("API called with correlation {CorrelationId}",
HttpContext.TraceIdentifier);
return Ok();
}
}
Multiple Destinations
services.AddLogging(builder =>
{
builder.AddSyslog(new List<SyslogServer>
{
new SyslogServer("primary-log", 514),
new SyslogServer("backup-log", 514)
}, enableConsole: true);
});
๐ Advanced Structured Logging
Rich Metadata
LogEntry entry = new LogEntry(Severity.Error, "Payment processing failed")
.WithProperty("OrderId", orderId)
.WithProperty("Amount", amount)
.WithProperty("Currency", "USD")
.WithProperty("PaymentProvider", "Stripe")
.WithProperty("ErrorCode", errorCode)
.WithCorrelationId(correlationId)
.WithSource("PaymentService")
.WithException(exception);
await log.LogEntryAsync(entry);
JSON Serialization
LogEntry entry = new LogEntry(Severity.Info, "User session")
.WithProperty("SessionDuration", TimeSpan.FromMinutes(45))
.WithProperty("PagesVisited", new[] { "/home", "/products", "/checkout" });
string json = entry.ToJson();
// Output: {"timestamp":"2023-12-01T10:30:00.000Z","severity":"Info","message":"User session","threadId":1,"properties":{"SessionDuration":"00:45:00","PagesVisited":["/home","/products","/checkout"]}}
โก Background Processing & Batching
Enable Background Queue
LoggingModule log = new LoggingModule("logserver", 514);
log.Settings.EnableBackgroundQueue = true;
log.Settings.BatchSize = 100; // Batch up to 100 messages
log.Settings.FlushInterval = 5000; // Force flush every 5 seconds
log.Settings.MaxMemoryEntries = 10000; // Queue up to 10K messages in memory
// Messages are now processed asynchronously in background
for (int i = 0; i < 100000; i++)
{
log.Info($"High-volume message {i}"); // Returns immediately
}
// Ensure all messages are processed before shutdown
await log.FlushAsync();
Persistent Queues
// Messages survive application restarts
log.Settings.EnablePersistentQueue = true;
log.Settings.QueueFilePath = "./logs/message-queue.dat";
log.Critical("This message will be delivered even if app crashes!");
๐ฏ Multiple Destinations
Syslog + Console + File
List<SyslogServer> servers = new List<SyslogServer>
{
new SyslogServer("primary-syslog", 514),
new SyslogServer("backup-syslog", 514)
};
LoggingModule log = new LoggingModule(servers, enableConsole: true);
log.Settings.FileLogging = FileLoggingMode.FileWithDate; // Creates dated files
log.Settings.LogFilename = "./logs/app.log";
log.Alert("This goes to 2 syslog servers, console, AND file!");
File-Only Logging
LoggingModule log = new LoggingModule("./logs/app.log", FileLoggingMode.SingleLogFile);
await log.InfoAsync("File-only message");
๐จ Console Colors & Formatting
Enable Colors
log.Settings.EnableColors = true;
log.Settings.Colors.Error = new ColorScheme(ConsoleColor.Red, ConsoleColor.Black);
log.Settings.Colors.Warning = new ColorScheme(ConsoleColor.Yellow, ConsoleColor.Black);
Custom Message Format with Rich Variables
// Basic format
log.Settings.HeaderFormat = "{ts} [{sev}] {host}:{thread}";
// Detailed production format
log.Settings.HeaderFormat = "{ts} {host}[{pid}] {sev} [T:{thread}] [{app}]";
// Performance monitoring format
log.Settings.HeaderFormat = "{ts} {host} CPU:{cpu} MEM:{mem}MB UP:{uptime} {sev}";
// Microservices format
log.Settings.HeaderFormat = "{ts} [{app}:{pid}] {sev} [{correlation}] [{source}]";
log.Settings.TimestampFormat = "yyyy-MM-dd HH:mm:ss.fff";
log.Settings.UseUtcTime = true;
Available Header Format Variables
Variable | Description | Example Output |
---|---|---|
{ts} |
Timestamp | 2024-01-15 14:30:25.123 |
{host} |
Machine name | web-server-01 |
{thread} |
Thread ID | 12 |
{sev} |
Severity name | Info |
{level} |
Severity number (0-7) | 6 |
{pid} |
Process ID | 1234 |
{user} |
Current username | john.doe |
{app} |
Application name | MyWebApp |
{domain} |
App domain | MyWebApp.exe |
{cpu} |
CPU core count | 8 |
{mem} |
Memory usage (MB) | 256 |
{uptime} |
Process uptime | 02:45:30 |
{correlation} |
Correlation ID | abc-123-def |
{source} |
Log source | UserService |
๐ก๏ธ Input Validation & Safety
All public properties now have comprehensive validation:
// Validates port range (0-65535)
server.Port = 65536; // โ Throws ArgumentOutOfRangeException
// Validates hostname not null/empty
server.Hostname = null; // โ Throws ArgumentException
// Validates minimum values
log.Settings.MaxMessageLength = 16; // โ Throws ArgumentOutOfRangeException (min: 32)
// Validates color schemes
log.Settings.Colors.Debug = null; // โ Throws ArgumentNullException
๐งช Testing with Integrated SyslogServer
The library now includes a complete SyslogServer for testing:
// Start a test syslog server
var serverSettings = new Syslog.Settings
{
UdpPort = 5140,
LogFileDirectory = "./test-logs/"
};
// Use with your logging client
LoggingModule log = new LoggingModule("127.0.0.1", 5140);
await log.InfoAsync("Test message");
// Server automatically logs to file for verification
๐ Performance Metrics
Sync vs Async Performance
// Measure sync performance
DateTime start = DateTime.UtcNow;
for (int i = 0; i < 1000; i++)
{
log.Info($"Sync message {i}");
}
await log.FlushAsync();
DateTime end = DateTime.UtcNow;
double syncMps = 1000.0 / (end - start).TotalSeconds;
// Measure async performance
start = DateTime.UtcNow;
List<Task> tasks = new List<Task>();
for (int i = 0; i < 1000; i++)
{
tasks.Add(log.InfoAsync($"Async message {i}"));
}
await Task.WhenAll(tasks);
await log.FlushAsync();
end = DateTime.UtcNow;
double asyncMps = 1000.0 / (end - start).TotalSeconds;
Console.WriteLine($"Sync: {syncMps:F0} msg/sec, Async: {asyncMps:F0} msg/sec");
๐ง Configuration Examples
Production Configuration
LoggingModule log = new LoggingModule("prod-syslog", 514, enableConsole: false);
// Enable background processing for high throughput
log.Settings.EnableBackgroundQueue = true;
log.Settings.BatchSize = 200;
log.Settings.FlushInterval = 10000;
// Enable persistence for reliability
log.Settings.EnablePersistentQueue = true;
log.Settings.QueueFilePath = "/var/log/app/message-queue.dat";
// Set appropriate filters
log.Settings.MinimumSeverity = Severity.Warning;
log.Settings.MaxMessageLength = 8192;
// Structured logging for analysis
await log.BeginStructuredLog(Severity.Info, "Application started")
.WithProperty("Version", Assembly.GetExecutingAssembly().GetName().Version)
.WithProperty("Environment", Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"))
.WithProperty("MachineName", Environment.MachineName)
.WriteAsync();
Development Configuration
LoggingModule log = new LoggingModule("localhost", 514, enableConsole: true);
// Immediate feedback for development
log.Settings.EnableBackgroundQueue = false;
log.Settings.EnableColors = true;
log.Settings.MinimumSeverity = Severity.Debug;
// File logging for detailed debugging
log.Settings.FileLogging = FileLoggingMode.FileWithDate;
log.Settings.LogFilename = "./logs/debug.log";
High-Concurrency Configuration
LoggingModule log = new LoggingModule("logserver", 514, enableConsole: true);
// Optimized for multi-threaded applications
log.Settings.EnableBackgroundQueue = true; // Essential for high concurrency
log.Settings.BatchSize = 500; // Larger batches for efficiency
log.Settings.FlushInterval = 2000; // Frequent flushing under load
log.Settings.MaxMemoryEntries = 50000; // Higher memory limit
log.Settings.EnableColors = true; // Safe - race conditions prevented
// Thread-safe server switching (safe during active logging)
Task.Run(async () =>
{
while (true)
{
// Even rapid server changes are thread-safe
log.Servers = GetAvailableServers();
await Task.Delay(1000);
}
});
// Multiple threads can safely log concurrently
Parallel.For(0, 1000, i =>
{
log.Info($"Concurrent message from thread {Thread.CurrentThread.ManagedThreadId}: {i}");
});
๐ Migration from v1.x
Breaking Changes
- Constructors have changed - update your initialization code
- Some method signatures now include
CancellationToken
parameters - Settings properties now have validation (may throw exceptions on invalid values)
New Recommended Patterns
// Old v1.x style
LoggingModule log = new LoggingModule("server", 514);
log.Log(Severity.Info, "Message");
// New v2.x style (both work, async preferred)
LoggingModule log = new LoggingModule("server", 514);
await log.InfoAsync("Message"); // โ
Preferred
log.Info("Message"); // โ
Still works
// New structured logging
await log.BeginStructuredLog(Severity.Info, "User action")
.WithProperty("Action", "Login")
.WithProperty("UserId", userId)
.WriteAsync();
๐๏ธ Architecture
- Thread-Safe: All operations are thread-safe with comprehensive locking and race condition prevention
- Console color operations properly isolated to prevent bleeding between threads
- UDP client management handles concurrent server configuration changes
- Background queue operations optimized for high-concurrency scenarios
- Settings modifications safe during concurrent logging operations
- Memory Efficient: Configurable memory limits with pressure handling and leak prevention
- I/O Optimized: Background batching reduces I/O operations with intelligent queue management
- Fault Tolerant: Persistent queues survive crashes and restarts with corruption recovery
- Standards Compliant: RFC 3164 syslog format support with proper message formatting
- Cross-Platform: Works on Windows, Linux, and macOS with platform-specific optimizations
๐ Documentation
- Developer Guide (CLAUDE.md) - Comprehensive development documentation
- API Reference - Generated XML documentation
- Performance Benchmarks - Detailed performance analysis
- Integration Examples - Comprehensive test suite with examples
๐งช Testing
Run the comprehensive test suite:
cd src/Test
dotnet run
The test program validates every library capability including:
- โ All constructor patterns and validation
- โ Sync and async logging methods
- โ Structured logging with properties and correlation IDs
- โ Background processing and persistent queuing
- โ Comprehensive thread safety under extreme concurrent load
- โ Multiple destination delivery (syslog + console + file)
- โ Persistent queue recovery across restarts
- โ Error handling and edge cases
- โ Performance benchmarks (>100K msg/sec)
- โ SyslogServer integration and end-to-end testing
Advanced Thread Safety Testing
The test suite includes 20+ specialized thread safety tests covering:
- Console color race condition prevention (50 concurrent threads)
- UDP client management during server configuration changes
- Background queue operations under extreme load (20 threads ร 100 messages)
- Settings modification race conditions (concurrent property changes)
- Disposal safety with active operations across multiple threads
- Exception handling thread safety (15 threads ร 20 exceptions)
- File handle management with concurrent file access
- Memory pressure testing under concurrent load
- Mixed sync/async operations validation
- Resource contention simulation with large message payloads
๐ค Help or Feedback
Found a bug or have a feature request? File an issue - we'd love to hear from you!
๐ Special Thanks
We'd like to extend a special thank you to those that have helped make this library better: @dev-jan @jisotalo
๐ Version History
Please refer to CHANGELOG.md for detailed version history.
โญ Star this repo if SyslogLogging has helped your project!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- System.Text.Json (>= 8.0.5)
-
.NETFramework 4.8
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- System.Text.Json (>= 8.0.5)
-
.NETStandard 2.0
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- System.Text.Json (>= 8.0.5)
-
.NETStandard 2.1
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- System.Text.Json (>= 8.0.5)
-
net6.0
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- System.Text.Json (>= 8.0.5)
-
net8.0
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- System.Text.Json (>= 8.0.5)
NuGet packages (18)
Showing the top 5 NuGet packages that depend on SyslogLogging:
Package | Downloads |
---|---|
Omnicx.WebStore.Core
OmniCX WebStore Core contains the Controllers, API SDK and Models required to run the MVC Views of the WebStore. |
|
BigQ.dll
BigQ is a messaging platform using TCP sockets and websockets featuring sync, async, channel, and private communications. |
|
ContainerFS
Self-contained single-user file system written in C#. |
|
Less3
<3 Less3 is S3-compatible object storage that you can run on your laptop, server, or anywhere you like. |
|
RestDb
RestDb is a platform that enables a RESTful API interface in front of Microsoft SQL Server, MySQL, PostgreSQL, and Sqlite databases. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
2.0.11 | 241 | 10/7/2025 |
2.0.10 | 388 | 9/22/2025 |
2.0.9 | 169 | 9/22/2025 |
2.0.8 | 5,989 | 1/7/2025 |
2.0.7 | 5,134 | 12/23/2024 |
2.0.6 | 780 | 10/17/2024 |
2.0.5 | 366 | 9/10/2024 |
2.0.4 | 197 | 9/10/2024 |
2.0.3 | 195 | 9/10/2024 |
2.0.2 | 13,787 | 8/1/2023 |
2.0.1.8 | 9,811 | 10/6/2022 |
2.0.1.7 | 21,833 | 11/19/2021 |
2.0.1.6 | 1,485 | 11/12/2021 |
2.0.1.5 | 4,398 | 9/13/2021 |
2.0.1.4 | 25,371 | 5/20/2021 |
2.0.1.3 | 4,616 | 3/11/2021 |
2.0.1.2 | 1,255 | 3/11/2021 |
2.0.1.1 | 1,222 | 3/10/2021 |
2.0.1 | 1,240 | 3/10/2021 |
1.3.2.7 | 8,979 | 12/2/2020 |
1.3.2.6 | 2,908 | 11/23/2020 |
1.3.2.5 | 2,277 | 11/15/2020 |
1.3.2.4 | 1,549 | 11/6/2020 |
1.3.2.3 | 5,588 | 9/10/2020 |
1.3.2.2 | 24,107 | 6/10/2020 |
1.3.2.1 | 9,401 | 5/8/2020 |
1.3.2 | 73,934 | 12/3/2019 |
1.3.1 | 11,696 | 10/27/2019 |
1.3.0 | 1,380 | 10/7/2019 |
1.2.1 | 4,472 | 9/21/2019 |
1.2.0 | 2,449 | 8/10/2019 |
1.1.0 | 794,631 | 7/30/2019 |
1.0.12 | 1,405 | 7/6/2019 |
1.0.11 | 1,529 | 6/12/2019 |
1.0.10 | 5,761 | 3/10/2019 |
1.0.9 | 17,624 | 9/11/2017 |
1.0.8 | 6,793 | 12/12/2016 |
Added async support, structured logging, background queuing, and Microsoft.Extensions.Logging integration