2e0cac4c41a449779ce74574ef3a6861615c194c
EonaCat.Logger.LogServer
Server Setup
-
Install SQL Server (or update connection string for other providers)
-
Update appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=LogCentral;Trusted_Connection=True;TrustServerCertificate=True"
},
"Logging": {
"LogLevel": {
"Default": "Information"
}
}
}
- Run the server:
dotnet run
- Create an API Key (via SQL or admin panel):
INSERT INTO Applications (Name, ApiKey, IsActive, CreatedAt)
VALUES ('MyApp', NEWID(), 1, GETUTCDATE())
Client Installation
Via NuGet Package Manager:
dotnet add package EonaCat.Logger.LogClient
Via Package Manager Console:
Install-Package EonaCat.Logger.LogClient
📖 Usage Examples
Basic Setup
using EonaCat.Logger.LogClient;
using EonaCat.Logger.LogClient.Models;
// Configure the client
var options = new LogCentralOptions
{
ServerUrl = "https://your-logcentral-server.com",
ApiKey = "your-api-key-here",
ApplicationName = "MyAwesomeApp",
ApplicationVersion = "1.0.0",
Environment = "Production",
BatchSize = 50,
FlushIntervalSeconds = 5
};
var logClient = new LogCentralClient(options);
Integration with EonaCat.Logger
using EonaCat.Logger;
using EonaCat.Logger.LogClient.Integration;
var loggerSettings = new LoggerSettings();
loggerSettings.UseLocalTime = true;
loggerSettings.Id = "TEST";
var logger = new LogManager(loggerSettings);
// Create the adapter
var adapter = new LogCentralEonaCatAdapter(loggerSettings, logClient);
// Now all EonaCat.Logger logs will be sent to LogCentral automatically
logger.Log("Application started", LogLevel.Info);
logger.Log("User logged in", LogLevel.Info, "Authentication");
Manual Logging
// Simple log
await logClient.LogAsync(new LogEntry
{
Level = LogLevel.Information,
Category = "Startup",
Message = "Application started successfully"
});
// Log with properties
await logClient.LogAsync(new LogEntry
{
Level = LogLevel.Information,
Category = "UserAction",
Message = "User performed action",
UserId = "user123",
Properties = new Dictionary<string, object>
{
["Action"] = "Purchase",
["Amount"] = 99.99,
["ProductId"] = "prod-456"
}
});
// Log exception
try
{
// Your code
throw new Exception("Something went wrong");
}
catch (Exception ex)
{
await logClient.LogExceptionAsync(ex, "Error processing order",
new Dictionary<string, object>
{
["OrderId"] = "12345",
["CustomerId"] = "cust-789"
});
}
Security Event Logging
await logClient.LogSecurityEventAsync(
"LoginAttempt",
"Failed login attempt detected",
new Dictionary<string, object>
{
["Username"] = "admin",
["IPAddress"] = "192.168.1.100",
["Attempts"] = 5
}
);
await logClient.LogSecurityEventAsync(
"UnauthorizedAccess",
"Unauthorized API access attempt",
new Dictionary<string, object>
{
["Endpoint"] = "/api/admin/users",
["Method"] = "DELETE",
["UserId"] = "user456"
}
);
Analytics Logging
// Track user events
await logClient.LogAnalyticsAsync("PageView",
new Dictionary<string, object>
{
["Page"] = "/products/electronics",
["Duration"] = 45.2,
["Source"] = "Google"
}
);
await logClient.LogAnalyticsAsync("Purchase",
new Dictionary<string, object>
{
["ProductId"] = "prod-123",
["Price"] = 299.99,
["Category"] = "Electronics",
["PaymentMethod"] = "CreditCard"
}
);
await logClient.LogAnalyticsAsync("FeatureUsage",
new Dictionary<string, object>
{
["Feature"] = "DarkMode",
["Enabled"] = true,
["Platform"] = "iOS"
}
);
ASP.NET Core Integration
// Program.cs or Startup.cs
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Register LogCentral
var logCentralOptions = new LogCentralOptions
{
ServerUrl = builder.Configuration["LogCentral:ServerUrl"],
ApiKey = builder.Configuration["LogCentral:ApiKey"],
ApplicationName = "MyWebApp",
ApplicationVersion = "1.0.0",
Environment = builder.Environment.EnvironmentName
};
var logClient = new LogCentralClient(logCentralOptions);
builder.Services.AddSingleton(logClient);
var app = builder.Build();
// Use middleware to log requests
app.Use(async (context, next) =>
{
var requestId = Guid.NewGuid().ToString();
await logClient.LogAsync(new LogEntry
{
Level = LogLevel.Information,
Category = "HTTP",
Message = $"{context.Request.Method} {context.Request.Path}",
RequestId = requestId,
Properties = new Dictionary<string, object>
{
["Method"] = context.Request.Method,
["Path"] = context.Request.Path.Value,
["QueryString"] = context.Request.QueryString.Value
}
});
await next();
});
app.Run();
}
}
Windows Service / Console App
using EonaCat.Logger.LogClient;
using Microsoft.Extensions.Hosting;
public class Worker : BackgroundService
{
private readonly LogCentralClient _logClient;
public Worker(LogCentralClient logClient)
{
_logClient = logClient;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await _logClient.LogAsync(new LogEntry
{
Level = LogLevel.Information,
Category = "Service",
Message = "Worker service started"
});
while (!stoppingToken.IsCancellationRequested)
{
try
{
// Your work here
await Task.Delay(1000, stoppingToken);
}
catch (Exception ex)
{
await _logClient.LogExceptionAsync(ex, "Error in worker");
}
}
await _logClient.FlushAndDisposeAsync();
}
}
WPF / WinForms Application
public partial class MainWindow : Window
{
private readonly LogCentralClient _logClient;
public MainWindow()
{
InitializeComponent();
_logClient = new LogCentralClient(new LogCentralOptions
{
ServerUrl = "https://logs.mycompany.com",
ApiKey = "your-api-key",
ApplicationName = "MyDesktopApp",
ApplicationVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(),
Environment = "Production"
});
Application.Current.DispatcherUnhandledException += OnUnhandledException;
}
private async void OnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
await _logClient.LogExceptionAsync(e.Exception, "Unhandled exception in UI");
e.Handled = true;
}
protected override async void OnClosing(CancelEventArgs e)
{
await _logClient.FlushAndDisposeAsync();
base.OnClosing(e);
}
}
🎯 Advanced Features
Correlation IDs for Distributed Tracing
var correlationId = Guid.NewGuid().ToString();
await logClient.LogAsync(new LogEntry
{
Level = LogLevel.Information,
Category = "OrderProcessing",
Message = "Order created",
CorrelationId = correlationId,
Properties = new Dictionary<string, object> { ["OrderId"] = "12345" }
});
// In another service
await logClient.LogAsync(new LogEntry
{
Level = LogLevel.Information,
Category = "PaymentProcessing",
Message = "Payment processed",
CorrelationId = correlationId, // Same ID
Properties = new Dictionary<string, object> { ["Amount"] = 99.99 }
});
Performance Monitoring
var stopwatch = Stopwatch.StartNew();
try
{
// Your operation
await SomeSlowOperation();
}
finally
{
stopwatch.Stop();
await logClient.LogAsync(new LogEntry
{
Level = LogLevel.Information,
Category = "Performance",
Message = "Operation completed",
Properties = new Dictionary<string, object>
{
["Operation"] = "DatabaseQuery",
["DurationMs"] = stopwatch.ElapsedMilliseconds,
["Status"] = "Success"
}
});
}
📊 Dashboard Features
- Real-time monitoring: Auto-refreshes every 30 seconds
- Advanced search: Full-text search across all log fields
- Filtering: By application, environment, level, date range
- Charts: Visual representation of log levels and trends
- Export: Download logs as CSV or JSON
- Alerts: Configure notifications for critical events (planned)
🔒 Security Best Practices
- Use HTTPS for production deployments
- Rotate API keys regularly
- Limit API key permissions by application
- Store API keys in secure configuration (Azure Key Vault, AWS Secrets Manager)
- Enable authentication for dashboard access (add authentication middleware)
🚀 Deployment
Docker Deployment
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "LogCentral.Server.dll"]
Azure Deployment
az webapp create --resource-group MyResourceGroup --plan MyPlan --name logcentral --runtime "DOTNETCORE:8.0"
az webapp deployment source config-zip --resource-group MyResourceGroup --name logcentral --src logcentral.zip
📈 Scalability
For high-volume applications:
- Use Redis for caching
- Implement Elasticsearch for faster searches
- Use message queues (RabbitMQ, Azure Service Bus) for async processing
- Partition database by date ranges
- Implement log archival and retention policies
Description
Languages
HTML
62.5%
C#
35.7%
CSS
1.6%
JavaScript
0.2%