serilog-mssql / serilog-sinks-mssqlserver

A Serilog sink that writes events to Microsoft SQL Server and Azure SQL
Apache License 2.0
276 stars 147 forks source link

NVarChar Columns with 1 data length gets their values truncated into empty strings #505

Closed Whinarn closed 8 months ago

Whinarn commented 8 months ago

Please clearly describe what the SQL Sink is doing incorrectly:

When you have a NVarChar column with max length of 1, it will incorrectly truncate the value to an empty string. This was first introduced in v6.4.0 with this PR: #490

Please clearly describe the expected behavior:

Values less than the max length shouldn't have to be truncated, and the full value should be stored.

List the names and versions of all Serilog packages used in the project:

Target framework and operating system:

.NET 7 Windows 11

Provide a simple reproduction of your Serilog configuration code:

var sinkOpts = new MSSqlServerSinkOptions() {
    TableName = "Logs"
};
var columnOpts = new ColumnOptions() {
    AdditionalColumns = new SqlColumn[]
    {
        new SqlColumn("TestColumn", SqlDbType.NVarChar, allowNull: false, dataLength: 1)
    }
};

var log = new LoggerConfiguration()
    .WriteTo.MSSqlServer(
        connectionString: "NOT_RELEVANT_HERE",
        sinkOptions: sinkOpts,
        columnOptions: columnOpts
    ).CreateLogger();