Closed DM-98 closed 23 hours ago
The Id column is default, this is why you are getting integer column. This code should help. However i strongly recommend using standard Id column as primary key. If you have any concerns, you can use BigInt type for large scale apps.
var colOpts = new ColumnOptions();
colOpts.Store.Remove(StandardColumn.Id);
SqlColumn customIdColumn = new("Id", System.Data.SqlDbType.UniqueIdentifier, allowNull: false);
colOpts.AdditionalColumns =[customIdColumn];
colOpts.PrimaryKey = customIdColumn;
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.MSSqlServer(connectionString: "your_conn_str",
sinkOptions: new MSSqlServerSinkOptions { AutoCreateSqlDatabase = false, AutoCreateSqlTable = false, TableName = "Logs" }, columnOptions: colOpts)
//.Enrich.With<YourCustomSerilogEnricher>() use enricher to fill id field
.CreateLogger();
Hi @DM-98!
Did the solution suggested by @cancakar35 work for you?
Closing issue due to inactivity.
Please clearly describe what the SQL Sink is doing incorrectly: It creates the table, but ignoring my setup which is to change "Id" column to a UniqueIdentifier.
Please clearly describe the expected behavior: I expect to change the "Id" datatype to UniqueIdentifier instead of Int.
List the names and versions of all Serilog packages used in the project:
(configuration, etc.):
Target framework and operating system: .NET 9