GithubHelp home page GithubHelp logo

christosmylonas / serilog.sinks.oracle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lucascebertin/serilog.sinks.oracle

0.0 1.0 0.0 45 KB

Sink for Serilog, flushes logs on Oracle

License: MIT License

C# 88.27% PowerShell 8.42% Shell 3.31%

serilog.sinks.oracle's Introduction

Serilog.Sinks.Oracle

This project is a port from Serilog.Sinks.MSSqlServerCore. It's a netstandard2 library to provide a clean way to send Serilog events to Oracle 11 (and possible 12 too).

Linux Build Windows Build

Gettins started

Prerequisites

On Windows, powershell (most up to date, please...)

PS C:\Path\To\The\Project> ./build.ps1

On Linux (be free!)

$ ./build.sh

Database Scripts

CREATE TABLE YOUR_TABLE_SPACE.LOG(
  "Id"                 INT             NOT NULL ENABLE,
  "Message"            CLOB            NULL,
  "MessageTemplate"    CLOB            NULL,
  "Level"              NVARCHAR2(128)  NULL,
  "TimeStamp"          TIMESTAMP       NOT NULL,
  "Exception"          CLOB            NULL,
  "Properties"         CLOB            NULL,
  "LogEvent"           CLOB            NULL
);

CREATE SEQUENCE YOUR_TABLE_SPACE.LOG_SEQUENCE START WITH 1 INCREMENT BY 1;

-- YOU CAN CHOOSE TO USE FUNCTION OR CREATE A TRIGGER... I PREFER THE TRIGGER WAY :) 
-- TRIGGER
CREATE TRIGGER 
	YOUR_TABLE_SPACE.LOG_TRIGGER 
BEFORE INSERT ON 
	YOUR_TABLE_SPACE.LOG 
REFERENCING 
	NEW AS NEW 
	OLD AS old 
FOR EACH ROW 
BEGIN 
	IF :new."Id" IS NULL THEN 
		SELECT 
			YOUR_TABLE_SPACE.LOG_SEQUENCE.NEXTVAL 
		INTO 
			:new."Id" 
		FROM dual; 
	END IF; 
END;


-- OR FUNCTION
CREATE FUNCTION YOUR_TABLE_SPACE.get_seq RETURN INT IS
BEGIN
  RETURN YOUR_TABLE_SPACE.LOG_SEQUENCE.NEXTVAL;
END;

Using it on your app

  //Don't forget to add the namespace, ok?

  var connectionString =
      "user id=system;password=oracle;data source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL = TCP)(HOST = localhost)(PORT = 49161)))(CONNECT_DATA=(SERVICE_NAME = xe)))";

  // If you choose to use the trigger just pass string.Empty in function name argument (tableSpaceAndFunctionName)
  var logger = new LoggerConfiguration()
	  .MinimumLevel.Verbose()
	  .WriteTo.Oracle(cfg => 
		  cfg.WithSettings(connectionString)
		  .UseBurstBatch() // or if you want to use PeriodicBatch, call .UsePeriodicBatch()
		  .CreateSink())
	  .CreateLogger();

  const string column = "ADDITIONALDATACOLUMN";
  var columnOptions = new ColumnOptions
  {
      AdditionalDataColumns = new List<DataColumn>
      {
          new DataColumn(column , typeof(string))
      }
  };

  Log.Logger = new LoggerConfiguration()
      //.Enrich.FromLogContext() /* uncomment this line if you want to store dynamic values and passing them by LogContext.PushProperty(name, value)... remember, this PushProperty is Disposable*/
      //.Enrich.WithProperty("column", "constant value, lika machine's hostname")  /* uncomment this line if you want to store a "constant value" */
      .MinimumLevel.Verbose()
      .WriteTo.Oracle(cfg =>
          cfg.WithSettings(logConnectionString, columnOptions: columnOptions)
          .UseBurstBatch()
          .CreateSink())
      .CreateLogger();


  //Be aware of the batch limit and delay time configured up here!
  logger.Debug("Yey, this message will be stored on Oracle!!");

Travis useful notes

At the root you will find a Docker file named Dockerfile.travis. To simulate, run this way:

docker build -t travis-ci-oracle -f Dockerfile.travis .
docker run -it travis-ci-oracle

IMPORTANT NOTES!

This repository and package are in early stages, so, use it on your own and risk but feel free to contribute opening issues or sending pull-requests!

serilog.sinks.oracle's People

Contributors

bduman avatar fproenca avatar driekus77 avatar lucascebertin avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.