Skip to content

Instantly share code, notes, and snippets.

@sametoz
Created May 3, 2020 08:18
Show Gist options
  • Save sametoz/eee1ce69c7223c278670fa96c1f85d19 to your computer and use it in GitHub Desktop.
Save sametoz/eee1ce69c7223c278670fa96c1f85d19 to your computer and use it in GitHub Desktop.
v2
public static void Main(string[] args)
{
var sinkOpts = new SinkOptions { TableName = "_Log", AutoCreateSqlTable = true, BatchPostingLimit = 10 };
//ColumnOptions: Veritabanı tablosunun özellikleri burada belirlenir.
//default oluşturulan sütunlar çıkartılabilir, veya yenileri eklenebilir.
var columnOptions = new ColumnOptions
{
AdditionalColumns = new Collection<SqlColumn>
{
new SqlColumn
{ColumnName = "UserName", PropertyName = "UserName", DataType = SqlDbType.NVarChar, DataLength = 64},
new SqlColumn
{ColumnName = "ApiPath", PropertyName = "ApiPath", DataType = SqlDbType.NVarChar, NonClusteredIndex = true}
}
};
//Serilog'un sunduğu ve işimize yaramayan iki sütunu kaldırıyorum.
columnOptions.Store.Remove(StandardColumn.MessageTemplate);
columnOptions.Store.Remove(StandardColumn.Properties);
Log.Logger = new LoggerConfiguration()
.WriteTo.MSSqlServer(
connectionString: appSettings.GetConnectionString("DB"),
sinkOptions: sinkOpts,
columnOptions: columnOptions,
restrictedToMinimumLevel: LogEventLevel.Error
).CreateLogger();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment