• 代码配置 Log4Net 的 AdoNetAppender


    今天发现 Log4Net 输出到不同数据库时,其 commandtext 使用的语法居然也不同,摸索了好一会,分享一下:

            // SqlServer
            //
            private const string SqlServerLog4NetCommandText = "INSERT INTO pacs_log ([Datetime],[ThreadID],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)"; 
            private const string SqlServerConnectionType = "System.Data.SqlClient.SqlConnection, System.Data, version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
            private static string SqlServerConnectionString(string dbHost, string dbName, string dbUser, string dbPwd)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("data source={0}", dbHost);
                sb.AppendFormat(";initial catalog={0}", dbName);
                sb.AppendFormat(";User ID={0};Password={1}", dbUser, dbPwd);
                sb.Append(";integrated security=false;persist security info=True;");
                return sb.ToString();
            }
    
            // MySql
            //
            private const string MySqlLog4NetCommandText = "INSERT INTO pacs_log (Datetime,ThreadID,Level,Logger,Message,Exception) VALUES (?log_date, ?thread, ?log_level, ?logger, ?message, ?exception)"; 
            private const string MySqlConnectionType = "MySql.Data.MySqlClient.MySqlConnection, MySql.Data, Version=6.4.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d";
            private static string MySqlConnectionString(string dbHost, string dbName, string dbUser, string dbPwd)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("data source={0}", dbHost);
                sb.AppendFormat(";initial catalog={0}", dbName);
                sb.AppendFormat(";User ID={0};Password={1};persist security info=True;", dbUser, dbPwd);
                return sb.ToString();
            }
  • 相关阅读:
    [BZOJ3195] [Jxoi2012]奇怪的道路
    Splay Tree
    区间DP复习
    Link Cut Tree
    [BZOJ2734] [HNOI2012]集合选数
    如何写出杀手级简历(针对程序员) (转)
    30个提高Web程序执行效率的好经验(转)
    Oracle中的SQL跟踪( 转)
    如何终止SQL Server中的用户进程(转)
    Will the real programmers please stand up?(转)
  • 原文地址:https://www.cnblogs.com/kesalin/p/log4net.html
Copyright © 2020-2023  润新知