我尝试使用 log4net 记录错误消息并使用 SQL 将它们保存到数据库中,但根本没有任何反应......我错过了什么吗?这是我的代码
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
hierarchy.Root.RemoveAllAppenders(); /*Remove any other appenders*/
log4net.Repository.Hierarchy.Logger rootLogger = hierarchy.Root;
rootLogger.Level = hierarchy.LevelMap["ERROR"];
AdoNetAppender ado = new AdoNetAppender();
ado.ConnectionType = "System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
ado.ConnectionString = ConfigurationManager.AppSettings["MSSQLConnectionString_nvn1"];
ado.CommandText = "INSERT INTO Log ([Date],[Thread],[Level],[Identity],[Username],[Logger],[Message]) VALUES (@log_date, @thread , @level , @identity , @username , @logger, @message)";
ado.BufferSize = 1;
ado.Threshold = log4net.Core.Level.Error;
AdoNetAppenderParameter logd = new AdoNetAppenderParameter();
logd.ParameterName = "@log_date";
logd.DbType = DbType.DateTime;
logd.Layout = new log4net.Layout.RawTimeStampLayout();
ado.AddParameter(logd);
...........
ado.ActivateOptions();
log4net.Config.BasicConfigurator.Configure(ado);
谢谢。
摘要:任何人都可以检查我的代码并尝试给我一些关于如何将错误消息从 log4net 保存到数据库中的建议。