Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

asp.net - Serilog not inserting logs into database table

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);
        }
    }
}
question from:https://stackoverflow.com/questions/65902020/serilog-not-inserting-logs-into-database-table

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...