Open LouisMach opened 2 months ago
I also opened this stackoverflow thread for it: https://stackoverflow.com/questions/78408990/serilog-sql-server-sink-not-filling-custom-column-and-no-error-in-selflog
Hi @LouisMach!
Thank you for getting in touch. From a first look at your sample program, I could not see anything that looks obviously wrong. So I will try and debug it once I have some time for it.
I compared your sample to our samples/WorkerServiceDemo where we also use a custom column (AdditionalColumn1) and everything related to the custom column looks similar except that our sample has different names for the column and the property while yours does not. But that is probably not the cause.
Investigation continues.
Hi @ckadluba, thank you very much for your answer. I'm glad to hear you are investigating, I'd love to get this to work. I tried to include all relevant code in the samples but I could not share the whole project since it's proprietary. If you have any issues with reproducing this I will try to create a full sample app to reproduce the problem.
I have tried to get your code to compile but it seems to be incomplete (e.g. builder is used but not defined in Program.cs). So, can you please put together a simple but full sample project which I can use? That would be great.
P.S.: I modified our WorkerServiceDemo to test and rule out if the problem is caused by setting the column and property names differently, like in your sample. And as I assumed, this did not cause any trouble.
Bug Report / Support Request Template
I have set up database logging which works, but my custom column is always null even though the property exists and I have added a mapping for the column. SelfLog to console and debug is enabled, but no error shows up. I can trigger a visible selflog by setting an invalid connection string, so I think selflogging is working correctly.
I expect Serilog to fill the column with the value of the property when the property matches the mapping. I also expect Serilog to emit an error on selflog when an error prevents writing to the column.
.NET 7.0 OS: Windows 10
https://gist.github.com/LouisMach/a6c41f017dcb2fcf3d7e2ea79d880c82#file-program-cs
None, set in code.
Code: https://gist.github.com/LouisMach/a6c41f017dcb2fcf3d7e2ea79d880c82#file-service-cs SQL script: https://gist.github.com/LouisMach/a6c41f017dcb2fcf3d7e2ea79d880c82#file-tbllog-sql
The property is correctly added to the properties and scope part of the log entry, this is the content of the property column:
If I set the wrong connection string, I get the following error in Console and Debug Output:
2024-04-30T08:11:32.8056928Z Unable to write batch of 1 log events to the database due to following error: Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
So it seems that errors from Serilog are being written, so I would expect error output when Serilog is unable to write to the column.