Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional Column (CorrelationId) Returning Null Value #527

Closed
ryanrolfe opened this issue Mar 14, 2024 · 5 comments
Closed

Additional Column (CorrelationId) Returning Null Value #527

ryanrolfe opened this issue Mar 14, 2024 · 5 comments

Comments

@ryanrolfe
Copy link

Bug Report / Support Request Template

If you are opening a feature request, you can ignore this template. Bug reports and requests for assistance usually require the same basic information described below. This will help us more quickly reproduce and investigate the problem you're reporting. (If you are using Serilog.Sinks.MSSqlServerCore, that package is deprecated, please switch to Serilog.Sinks.MSSqlServer before reporting an issue.)

Please clearly describe what the SQL Sink is doing incorrectly:
When adding an additional column for the CorrelationId, NULL is stored in the database table. This code works with version 6.3.0 of Serilog.Sinks.MSSqlServer but later versions don't save the CorrelationId. I can see the CorrelationId in both the LogEvent and Properties Columns.
I have tried with and without the PropertyName being specified and also with different DataLength values.
Other columns such as RequestUri work as expected.

Please clearly describe the expected behavior:
The CorrelationId column should be populated

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

  • Serilog: 3.1.1
  • Serilog.Sinks.MSSqlServer: 6.6.0 (Issue occurs on version 6.4.0 and above)
  • (configuration, etc.)

Target framework and operating system:

[X] .NET 6
[ ] .NET Framework 4.8
[ ] .NET Framework 4.7
[ ] .NET Framework 4.6
OS:
Windows 10

Provide a simple reproduction of your Serilog configuration code:
var columnOptions = new ColumnOptions
{
AdditionalColumns = new Collection
{
new SqlColumn { ColumnName = "CorrelationId", PropertyName = "CorrelationId", DataType = SqlDbType.NVarChar},
new SqlColumn { ColumnName = "RequestUri", DataType = SqlDbType.NVarChar},
new SqlColumn { ColumnName = Constants.ApplicationKey, DataType = SqlDbType.VarChar },
new SqlColumn { ColumnName = Constants.InstanceKey, DataType = SqlDbType.VarChar }
}
};

serilogConfig
.WriteTo
.MSSqlServer(
connectionString,
sinkOptions: new MSSqlServerSinkOptions
{
TableName = "serilog",
SchemaName = "dbo",
AutoCreateSqlTable = true,
EagerlyEmitFirstEvent = Convert.ToBoolean(appenderConfig.Args["eagerlyEmitFirstEvent"]),
BatchPostingLimit = Convert.ToInt32(appenderConfig.Args["batchPostingLimit"])
},
columnOptions: columnOptions,
restrictedToMinimumLevel: level);

Provide a simple reproduction of your Serilog configuration file, if any:

Provide a simple reproduction of your application code:

@ryanrolfe
Copy link
Author

Just to provide an update on this, the DataType for the CorrelationId column needs to be SqlDbType.UniqueIdentifier in order for it to be populated in the database table.

This appears to be a breaking change between version 6.3.0 and 6.4.0.

@ckadluba
Copy link
Member

ckadluba commented Mar 18, 2024

Hi @ryanrolfe!

Thank you for telling us your finding. Can you please provide a small sample program which generates a log event that leads to a NULL value in the CorrelationId column? Thank you!

@ckadluba
Copy link
Member

ckadluba commented May 6, 2024

Perhaps this problem is fixed with #515 which is fixed in the latest dev build on nuget.org. Can you please confirm this?

@pkokay
Copy link

pkokay commented Aug 12, 2024

I am not the OP, but have a similar problem with versions 6.4.0+ of the Serilog.Sinks.MSSqlServer package, and the newest dev version did not fix it for me. Would it be best to open a different issue and provide a sample program?

@ckadluba
Copy link
Member

@pkokay yes, please do that. I will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants