I created a table in my database and i want to store my log information in this table. I used that code which is located here https://github.com/lucascebertin/Serilog.Sinks.Oracle. More specific i used :
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();
How can i define the table and the column where i want to store my log information?
There is an optional Parameter tableSpaceAndTableName
in the WithSettings(connectionString)
call.
Edit:
var logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Oracle(cfg =>
cfg.WithSettings(connectionString, tableSpaceAndTableName: "MyLogTable")
.UseBurstBatch() // or if you want to use PeriodicBatch, call .UsePeriodicBatch()
.CreateSink())
.CreateLogger();
Edit 2:
For adding new columns:
const string column = "ADDITIONALDATACOLUMN";
var columnOptions = new ColumnOptions
{
AdditionalDataColumns = new List<DataColumn>
{
new DataColumn(column , typeof(string))
}
};
and pass it to the columnOptions
parameter in WithSettings
new LoggerConfiguration()
.Enrich.WithProperty("ADDITIONALDATACOLUMN", "MyValue") /* uncomment this line if you want to store a "constant value" */
.MinimumLevel.Verbose()
.WriteTo.Oracle(cfg =>
cfg.WithSettings(logConnectionString, columnOptions: columnOptions)
.UseBurstBatch()
.CreateSink())
.CreateLogger();
You can add this as a static value if you pass it via Enrich.WithProperty
or add it in you log messages should in theory also set the column (didn't tested it) depends on your use case what you need.