pescuma / serilog-sinks-mysql

A Serilog sink that writes events to MySQL
Apache License 2.0
0 stars 0 forks source link

How to use this ?? #1

Open avinashmumbai1 opened 5 years ago

avinashmumbai1 commented 5 years ago

Found something

Code string connectionString = "Uid=serilog;Pwd=serilog;Server=localhost;Port=3306;Database=logs;"; string tableName = "logs";

// Used columns (Key is a column name) // Column type is writer's constructor parameter IDictionary<string, ColumnWriterBase> columnWriters = new Dictionary<string, ColumnWriterBase> { { "message", new RenderedMessageColumnWriter(DbType.String) }, { "message_template", new MessageTemplateColumnWriter(DbType.String) }, { "level", new LevelColumnWriter(true, DbType.String) }, { "raise_date", new TimestampColumnWriter(DbType.DateTimeOffset) }, { "exception", new ExceptionColumnWriter(DbType.String) }, { "properties", new LogEventSerializedColumnWriter(DbType.String) }, { "props_test", new PropertiesColumnWriter(DbType.String) }, { "machine_name", new SinglePropertyColumnWriter("MachineName", PropertyWriteMethod.Raw, DbType.String) } };

var logger = new LoggerConfiguration() .WriteTo.MySQL(connectionString, tableName, columnWriters) .CreateLogger();

But I dont know how do I use this ??

Can you provide any implementation of serilog-sinks-mysql

pescuma commented 5 years ago

You need, at least:

var logger = new LoggerConfiguration()
                           .WriteTo.MySQL(connectionString)
                           .CreateLogger();

If you want the log table to be created automatically:

var logger = new LoggerConfiguration()
                           .WriteTo.MySQL(connectionString, autoCreateSqlTable: true)
                           .CreateLogger();

If you want to change the log table name:

var logger = new LoggerConfiguration()
                           .WriteTo.MySQL(connectionString, tableName: "tab_log")
                           .CreateLogger();

If you want to store some properties as columns in the log table:

var logger = new LoggerConfiguration()
                           .WriteTo.MySQL(connectionString,
                                          aditionalColumns: cs => cs //
                                                 .AddColumnForProperty("PropertyName", "COLUMN_TYPE", "COLUMN_NAME"))
                           .CreateLogger();