Added multiple providers

This commit is contained in:
2025-04-26 10:56:32 +02:00
parent 83e2d37f41
commit b50ab3784c
23 changed files with 848 additions and 4 deletions

View File

@@ -380,6 +380,81 @@ private void LogHelper_OnException(object sender, ErrorMessage e)
}
```
Example of Discord Logging:
```csharp
loggingBuilder.AddEonaCatDiscordLogger(options =>
{
options.WebhookUrl = "https://discord.com/api/webhooks/your_webhook_here";
});
```
Example of Slack Logging:
```csharp
loggingBuilder.AddEonaCatSlackLogger(options =>
{
options.WebhookUrl = "https://hooks.slack.com/services/your_webhook_here";
});
```
Example of DatabaseLogging:
Create the table:
```csharp
CREATE TABLE Logs (
Id INT IDENTITY(1,1) PRIMARY KEY, -- SERIAL for PostgreSQL, AUTO_INCREMENT for MySQL
Timestamp DATETIME NOT NULL,
LogLevel NVARCHAR(50),
Category NVARCHAR(255),
Message NVARCHAR(MAX),
Exception NVARCHAR(MAX),
CorrelationId NVARCHAR(255)
);
```
MySQL:
```csharp
using MySql.Data.MySqlClient;
loggingBuilder.AddEonaCatDatabaseLogger(options =>
{
options.DbProviderFactory = MySqlClientFactory.Instance;
options.ConnectionString = "Server=localhost;Database=EonaCatLogs;User=root;Password=yourpassword;";
});
```
SQL Server:
```csharp
using Microsoft.Data.SqlClient;
loggingBuilder.AddEonaCatDatabaseLogger(options =>
{
options.DbProviderFactory = SqlClientFactory.Instance;
options.ConnectionString = "Server=localhost;Database=EonaCatLogs;User Id=sa;Password=yourpassword;";
});
```
PostgreSQL:
```csharp
using Npgsql;
loggingBuilder.AddEonaCatDatabaseLogger(options =>
{
options.DbProviderFactory = NpgsqlFactory.Instance;
options.ConnectionString = "Host=localhost;Database=EonaCatLogs;Username=postgres;Password=yourpassword;";
});
```
Example of batching database logging:
```csharp
loggingBuilder.AddEonaCatBatchingDatabaseLogger(options =>
{
options.DbProviderFactory = MySql.Data.MySqlClient.MySqlClientFactory.Instance;
options.ConnectionString = "Server=localhost;Database=EonaCatLogs;User=root;Password=yourpassword;";
options.BatchInterval = TimeSpan.FromSeconds(10); // Flush every 10 seconds
});
```
Example of adding custom context to the log messages:
```csharp