0

I am trying to create a log table using Serilog but it does not insert into the table with no errors .

connection string is right but I still don't understand why it dose not insert please help me to fix this problem

I am a beginner with logging so please give me answer with details

namespace QueuingSystemApp.Models
{
    public class HelperDB
    {
        private static readonly ILogger Errorlog;
        private static readonly ILogger Warninglog;
       
        private static readonly string ConnectionString =
         ConfigurationManager.ConnectionStrings["QueueingSystemEntities"].ConnectionString.ToString();
     

        static HelperDB()
        {
            Consollog = new LoggerConfiguration().WriteTo.Debug().CreateLogger();

            Errorlog = new LoggerConfiguration()
                .MinimumLevel.Error()
                .WriteTo.MSSqlServer(ConnectionString, "Serilogs")
                .CreateLogger();

            Warninglog = new LoggerConfiguration()
                .MinimumLevel.Warning()
                .WriteTo.MSSqlServer(ConnectionString, "Serilogs")
                .CreateLogger();
        }

        public static void WriteError( string message, int userid , int actionlog)
        {
            //Error - indicating a failure within the application or connected system
            Errorlog.Write(LogEventLevel.Error,  message, "{UserID}{LogAction}", userid,actionlog );
        }

        public static void WriteWarning(Exception ex, string message)
        {
            //Warning - indicators of possible issues or service / functionality degradation
            Warninglog.Write(LogEventLevel.Warning, ex, message);
        }
    }
}
Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
Bayan Zaza
  • 13
  • 5
  • 1
    Does this answer your question? [Serilog MSSQL Sink doesn't write logs to database](https://stackoverflow.com/questions/52953060/serilog-mssql-sink-doesnt-write-logs-to-database) – C. Augusto Proiete Jan 26 '21 at 14:36
  • There are a number of troubleshooting steps you can do, which are described here: https://stackoverflow.com/a/52960592/211672 – C. Augusto Proiete Jan 26 '21 at 14:38

0 Answers0