The C# SDK for NeuralLog provides a client library for interacting with the NeuralLog server from C# applications. It offers a familiar logging API and adapters for popular .NET logging frameworks.
- .NET 9.0 or later
# Install via NuGet Package Manager
Install-Package NeuralLog.SDK
# Or using .NET CLI
dotnet add package NeuralLog.SDKusing NeuralLog.SDK;
using System.Collections.Generic;
// Configure the SDK
var config = new NeuralLogConfig
{
ServerUrl = "http://localhost:3030",
Namespace = "default",
AsyncEnabled = true,
BatchSize = 100,
BatchIntervalMs = 5000
};
NeuralLog.Configure(config);
// Get a logger
var logger = NeuralLog.GetLogger("my-application");
// Log a simple message
logger.Info("Hello, world!");
// Log with structured data
var data = new Dictionary<string, object>
{
["user"] = "john.doe",
["action"] = "login",
["ip"] = "192.168.1.1"
};
logger.Info("User logged in", data);
// Log an error with exception
try
{
// Some code that might throw an exception
throw new System.Exception("Something went wrong");
}
catch (System.Exception ex)
{
logger.Error("Failed to process request", ex);
}The C# SDK supports various configuration options:
var config = new NeuralLogConfig
{
// Required settings
ServerUrl = "https://logs.example.com",
Namespace = "production",
// Optional settings
ApiKey = "your-api-key",
BatchSize = 100,
BatchIntervalMs = 5000,
MaxRetries = 3,
RetryBackoffMs = 1000,
AsyncEnabled = true,
DebugEnabled = false,
// HTTP client settings
Timeout = TimeSpan.FromSeconds(30),
MaxConnections = 10,
// Custom HTTP headers
Headers = new Dictionary<string, string>
{
["X-Custom-Header"] = "value"
}
};
NeuralLog.Configure(config);// Set global context data for all loggers
NeuralLog.SetGlobalContext(new Dictionary<string, object>
{
["application"] = "my-application",
["environment"] = "production",
["version"] = "1.0.0"
});
// Set logger-specific context data
logger.SetContext(new Dictionary<string, object>
{
["service"] = "user-service",
["instance"] = "user-service-1"
});The SDK supports batching of log messages to improve performance:
var config = new NeuralLogConfig
{
ServerUrl = "http://localhost:3030",
Namespace = "default",
AsyncEnabled = true,
BatchSize = 100,
BatchIntervalMs = 5000
};
NeuralLog.Configure(config);With batching enabled, log messages are queued and sent in batches when:
- The batch size is reached
- The batch interval elapses
- The
Flushmethod is called
To ensure all pending log messages are sent, you can flush the logger:
// Flush a specific logger
await logger.Flush();
// Flush all loggers
await NeuralLog.FlushAll();The NeuralLog C# SDK can be integrated with popular .NET logging frameworks. Framework-specific adapters will be added in future releases.
# Clone the repository
git clone https://github.com/NeuralLog/csharp.git
cd csharp
# Build the solution
dotnet build
# Run the tests
dotnet testDetailed documentation is available in the docs directory:
For integration guides and tutorials, visit the NeuralLog Documentation Site.
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.
- NeuralLog Auth - Authentication and authorization
- NeuralLog Server - Core server functionality
- NeuralLog Web - Web interface components
- NeuralLog TypeScript Client SDK - TypeScript client SDK
- NeuralLog Java Client SDK - Java client SDK
- NeuralLog Python SDK - Python SDK
MIT