https://github.com/skimmenthal13/serilog.sinks.database
Serilog sink that writes in one of these five databases (SqlServer, Oracle, MySql, PostgreSQL, Sqlite)
https://github.com/skimmenthal13/serilog.sinks.database
database logging mysql oracle postgresql serilog serilog-sink sink sqlite sqlserver
Last synced: 6 months ago
JSON representation
Serilog sink that writes in one of these five databases (SqlServer, Oracle, MySql, PostgreSQL, Sqlite)
- Host: GitHub
- URL: https://github.com/skimmenthal13/serilog.sinks.database
- Owner: Skimmenthal13
- License: mit
- Created: 2024-09-17T13:50:34.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-09-27T16:05:44.000Z (over 1 year ago)
- Last Synced: 2025-01-18T12:16:17.729Z (over 1 year ago)
- Topics: database, logging, mysql, oracle, postgresql, serilog, serilog-sink, sink, sqlite, sqlserver
- Language: C#
- Homepage: https://www.nuget.org/packages/Serilog.Sinks.Database
- Size: 47.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Serilog.Sinks.Database
Serilog sink that writes in one of these five databases :
| Database | Library | Example of connection string |
| ---------- | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| SqlServer | System.Data.SqlClient | const string sqlConnectionString = "Data Source=NBK-437;Persist Security Info=True;Initial Catalog=test;Integrated Security=SSPI;"; |
| Oracle | Oracle.ManagedDataAccess | const string oraConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XEPDB1)));User Id=DBWUSR;Password=DBWUSR;"; |
| MySql | MySql.Data | const string mysConnectionString = "Server=localhost;Database=test;Uid=sa;Pwd=ASqlAdmin01;"; |
| PostgreSQL | Npgsql | const string posConnectionString = "Server=127.0.0.1;Port=5432;Database=test;User Id=postgres;Password=ASqlAdmin01;"; |
| Sqlite | Microsoft.Data.Sqlite | const string litConnectionString = @"Data Source=c:\temp\test.db;"; |
## Getting started
Install [Serilog.Sinks.Database](https://www.nuget.org/packages/Serilog.Sinks.Database) from NuGet
```PowerShell
Install-Package Serilog.Sinks.Database
```
Configure logger by calling WriteTo.Database
```C#
DBType dbType = DBType.MySql;
var logger = new LoggerConfiguration()
.WriteTo.Database(dbType, "Server=localhost;Database=test;Uid=sa;Pwd=ASqlAdmin01;", "SerLogs",Events.LogEventLevel.Verbose,false,1)
.CreateLogger();
logger.Information("This informational message will be written to wich database you want");
```