1

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,

Maz
  • 41
  • 1
  • 5

3 Answers3

2

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...")
SunilA
  • 513
  • 8
  • 19
0

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.

C. Augusto Proiete
  • 24,684
  • 2
  • 63
  • 91
  • It's actually not easy, I tried. OracleBulkCopy will not insert into a table that has triggers. I tried using a trigger to increment the ID primary key by way of a sequence. So then I tried using a guid, and that turns out to be difficult because you store a guid as RAW(16) in oracle and in c# you put it in a byte array. I could not get Oracle to map that id column (stored as System.Byte[]) to the raw. What this means is that it won't be that straightforward to copy the MS SQL Server sink, not that it can't be done. Not sure if I will continue my effort. – CoderSteve Jul 21 '16 at 13:35
0

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

https://github.com/lucascebertin/Serilog.Sinks.Oracle

Arunprasanth K V
  • 20,733
  • 8
  • 41
  • 71