-
Notifications
You must be signed in to change notification settings - Fork 148
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
ERROR: Serilog.Core.Sinks.Batching.BatchingSink: failed emitting a batch The given ColumnMapping does not match up with any column in the source or destination. #606
Comments
Hello @Eruoghene! Thank you for reporting this. Can you please provide the SQL definition of your log table? Thank you, |
Perhaps the problem is, that you do not have most of the sinks standard columns (Message, Level, TimeStamp, etc.) in your table. You have to explicitly remove them in your |
Hi, I implemented the above recommendations as shown below Column Options definition was updated to below
Custom Table was updated to the below script (note that it has the standard columns)
Then the application code was updated to the code sample below (note there was no sample in the documentation for this application)
I used the below documentation
And I got the error below
|
Maybe that was a bit too much. I noticed that you also removed the Id standard column but your table has that column. |
Lolzzz, What was a bit too much? For the Custom columns, when Sink creates the ID column, looking at the table definition, its created without the Identity Constraint. Else why I created it |
I think the problem is as follows. Your table has a column named "Id" which is not nullable CREATE TABLE [dbo].[Logs](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
... In your code you removed the standard column "Id". columnOptions.Store.Remove(StandardColumn.Id); You also do not define a custom column with the name "Id". AdditionalColumns = new Collection
{
new SqlColumn { ColumnName = "SessionId", DataType = System.Data.SqlDbType.NVarChar, DataLength = 50, AllowNull = true },
new SqlColumn { ColumnName = "MethodName", DataType = System.Data.SqlDbType.NVarChar, DataLength = 50, AllowNull = true },
new SqlColumn { ColumnName = "ClientIP", DataType = System.Data.SqlDbType.NVarChar, DataLength = 20, AllowNull = true }
} As a consequence the sink issues an insert operation to the table where the Id column is missing and the SqlClient library throws an exception. I would suggest to not remove the standard column "Id". |
Hi, Kindly find a list of scenarios I ran:
I got database entries, but data did not enter my custom columns. In the screenshot below, all custom column have null values, even though I am passing values in the application code as shown below
The Message and Message template columns of serilog have exactly the same values which are string concatenation of items I would Like to be in individual columns for easy data search. The whole Idea was for me to be able to define specific columns and insert data into those columns via serilog. Do you have a working example? |
Yes. there is a sample on how to work with custom columns. Have you checked out https://github.com/serilog-mssql/serilog-sinks-mssqlserver/tree/dev/sample/WorkerServiceDemo? Be aware that the column options definition is in appsettings.json of this project. |
// Configure MSSqlServerSinkOptions
var sinkOptions = new MSSqlServerSinkOptions
{
TableName = "Logs", // Replace with your table name
AutoCreateSqlTable = false, // Automatically create the table if it doesn't exist
BatchPostingLimit = 1, // Post each log individually for debugging
BatchPeriod = TimeSpan.FromSeconds(5)
};
// log SelfLog to a file
var selfLogFile = Path.Combine(Directory.GetCurrentDirectory(), "serilog_selflog.txt");
SelfLog.Enable(File.CreateText(selfLogFile));
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.MSSqlServer(
connectionString: Configuration.GetSection("AppSettings").GetValue("DDSLDbConnection"),
sinkOptions: sinkOptions,
columnOptions: columnOptions)
.CreateLogger();
The text was updated successfully, but these errors were encountered: