I've been looking for a serilog sink for connecting to Oracle but no find anyone. Is there some way to connect with an Oracle database?
If not, is possible to connect at least with MySql??
Thanks,
Following is the snippet from my dotnet core api POC where i used Serilog to log into Oracle database.
First download the required packages -
dotnet add package Serilog.AspNetCore
dotnet add pacakage Serilog.Settings.Configuration
dotnet add package Serilog.Sinks.Oracle
Use the code in Program.cs class
using Serilog;
Code in Main method -
var connectionString =
@"user id=system;password=oracle;data source=
(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL = TCP)(HOST = localhost)
(PORT = 49161)))(CONNECT_DATA=(SERVICE_NAME = xe)))";
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.Oracle(cfg =>
cfg.WithSettings(connectionString)
.UseBurstBatch()
.CreateSink())
.CreateLogger();
Log.Information("Writing Logs in Oracle Database...")
There is no Serilog Sink for Oracle nor MySql at the moment.
Your best bet, would be to write one based on the MS SQL Server Sink: https://github.com/serilog/serilog-sinks-mssqlserver using the right ADO .NET connector for the database you're targeting.
Should be pretty easy.
Serilog sink for oracle is available now
The new oracle sink is netstandard2
library to provide a clean way to send Serilog events to Oracle 11 (and possible 12 too).
You can refer the below link for getting more idea