0

I'm using SerlLog with SQL Server and after configuration I have the following table in SQL Server:

enter image description here

I want to add data to the columns Message LikeExpression and other columns for occurrence.

I tried the following code

Log.ForContext("Message", "Some Message")
   .ForContext("LikeExpression", ex.Message)
   .Fatal("{StackTrace}", ex.Message, ex.StackTrace);

and this adds the following data to the table

enter image description here

I must have the Some Message string in Message column but it does not work any help please?

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
  • 2
    Per the guidelines please don't post images for schema and data. Post it in text format. You can edit your question to do so, which I recommend doing. – squillman Oct 20 '21 at 17:04
  • 1
    It's a **column** - not a "culomn" .... – marc_s Oct 20 '21 at 18:50
  • Your question is ok but we need you follow the guidelines about the code. Please avoid the use of images on code, schema and data and put it as text format. – Ali Briceño Oct 20 '21 at 21:00

1 Answers1

0

Finally I found the answer: I just reomoved the column Message from the table as it consider a stundered column by using xml configuration like this

<RemoveStandardColumns>
      **<remove Name="Message"/>**
      <remove Name="MessageTemplate"/>
      <remove Name="Level"/>
      <remove Name="LogEvent"/>
      <remove Name="Exception"/>
      <remove Name="TimeStamp"/>
    </RemoveStandardColumns>

then add it again as an ordinary column in c# using

new SqlColumn
                        {ColumnName = "Message", DataType = SqlDbType.VarChar, DataLength = 1024},

then to add data log to this table using serilog I used the following

         try
            {
                int b = 0;
                int a = 1 / b;
            }
            catch (Exception ex)
            {
                int x = OccuranceCalc("SCA");
                Log.ForContext("Message", "some Message")
                    .ForContext("LikeExpression", ex.Message)
                    .ForContext("OccurrenceCount", 1)
                    .ForContext("LastOccurrence", DateTime.Now)
                    .Fatal("{StackTrace}", ex.StackTrace);
            }