use Serilog.Sinks.Oracle package ---------------------------------------------------- #program file builder.Host.UseSerilog((context, loggerConfiguration) => loggerConfiguration .WriteTo.Console() .ReadFrom.Configuration(context.Configuration) .Enrich.FromLogContext() .WriteTo.Oracle(cfg => cfg.WithSettings(builder.Configuration.GetConnectionString("DefaultConnection")/*, columnOptions: columnOptions*/) .UseBurstBatch() .CreateSink())); ---------------------------------------------------- #migration protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.Sql(@" CREATE TABLE 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 ); "); migrationBuilder.Sql("CREATE SEQUENCE LOG_SEQUENCE START WITH 1 INCREMENT BY 1;"); migrationBuilder.Sql(@" CREATE TRIGGER LOG_TRIGGER BEFORE INSERT ON LOG REFERENCING NEW AS NEW OLD AS old FOR EACH ROW BEGIN IF :new.""Id"" IS NULL THEN SELECT LOG_SEQUENCE.NEXTVAL INTO :new.""Id"" FROM dual; END IF; END; "); migrationBuilder.Sql("CREATE FUNCTION get_seq RETURN INT IS BEGIN RETURN LOG_SEQUENCE.NEXTVAL; END; "); } /// <inheritdoc /> protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.Sql(" DROP TABLE LOG "); migrationBuilder.Sql("DROP SEQUENCE LOG_SEQUENCE"); migrationBuilder.Sql("DROP TRIGGER LOG_TRIGGER"); migrationBuilder.Sql("DROP FUNCTION get_seq"); } ---------------------------------------------------- #AppSetting "Serilog": { "MinimumLevel": { "Default": "Error", "Override": { "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Warning" } }, "Filter": [ { "Name": "ByExcluding", "Args": { "expression": "@mt = 'An unhandled exception has occurred while executing the request.'" } } ], "WriteTo": [ { "Name": "File", "Args": { "path": "./logs/log-.txt", "rollingInterval": "Day" } } ] },
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter