예제 #1
1
        /// <summary>
        /// 使用SQLSERVER记录异常日志
        /// </summary>
        /// <Author>Ryanding</Author>
        /// <date>2011-05-01</date>
         static void LoadADONetAppender(string conString)
        {
            LoadFileAppender();

            log4net.Repository.Hierarchy.Hierarchy hier =
              log4net.LogManager.GetLoggerRepository() as log4net.Repository.Hierarchy.Hierarchy;

            if (hier != null)
            {
                log4net.Appender.AdoNetAppender adoAppender = new log4net.Appender.AdoNetAppender();
                adoAppender.Name = "AdoNetAppender";
                adoAppender.CommandType = CommandType.Text;
                adoAppender.BufferSize = 1;
                adoAppender.ConnectionType = "System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
                adoAppender.ConnectionString = conString;
                adoAppender.CommandText = @"INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)";
                adoAppender.AddParameter(new AdoNetAppenderParameter { ParameterName = "@log_date", DbType = System.Data.DbType.DateTime, Layout = new log4net.Layout.RawTimeStampLayout() });
                adoAppender.AddParameter(new AdoNetAppenderParameter { ParameterName = "@thread", DbType = System.Data.DbType.String, Size = 255, Layout = new Layout2RawLayoutAdapter(new PatternLayout("%thread")) });
                adoAppender.AddParameter(new AdoNetAppenderParameter { ParameterName = "@log_level", DbType = System.Data.DbType.String, Size = 50, Layout = new Layout2RawLayoutAdapter(new PatternLayout("%level")) });
                adoAppender.AddParameter(new AdoNetAppenderParameter { ParameterName = "@logger", DbType = System.Data.DbType.String, Size = 255, Layout = new Layout2RawLayoutAdapter(new PatternLayout("%logger")) });
                adoAppender.AddParameter(new AdoNetAppenderParameter { ParameterName = "@message", DbType = System.Data.DbType.String, Size = 4000, Layout = new Layout2RawLayoutAdapter(new PatternLayout("%message")) });
                adoAppender.AddParameter(new AdoNetAppenderParameter { ParameterName = "@exception", DbType = System.Data.DbType.String, Size = 4000, Layout = new Layout2RawLayoutAdapter(new ExceptionLayout()) });
                adoAppender.ActivateOptions();
                BasicConfigurator.Configure(adoAppender);
            }


        }
예제 #2
0
        /// <summary>
        /// Returns a configured AdoNetAppender.
        /// </summary>
        /// <param name="connectionString">SqlConnectionString for the logging database.</param>
        /// <param name="tableName">Table to save logs to.</param>
        /// <param name="level">The level to log at.</param>
        /// <returns>A configured AdoNetAppender.</returns>
        public static AdoNetAppender GetSqlLogAppender(string connectionString, string tableName, Level level)
        {
            var appender = new AdoNetAppender
            {
                BufferSize = 1,
                ConnectionType = typeof(SqlConnection).AssemblyQualifiedName,
                ConnectionString = connectionString,
                CommandText = "INSERT INTO " + tableName + " (Date, Level, Logger, Message, Exception) VALUES (@date, @level, @logger, @message, @exception)",
                Threshold = level
            };

            appender.AddParameter(new AdoNetAppenderParameter
                                      {
                                          ParameterName = "@date",
                                          DbType = DbType.DateTime,
                                          Layout = new RawTimeStampLayout()

                                      });
            appender.AddParameter(new AdoNetAppenderParameter
                                      {
                                          ParameterName = "@level",
                                          DbType = DbType.String,
                                          Size = -1,
                                          Layout = new Layout2RawLayoutAdapter(new PatternLayout("%level"))
                                      });

            appender.AddParameter(new AdoNetAppenderParameter
                                      {
                                          ParameterName = "@logger",
                                          DbType = DbType.String,
                                          Size = -1,
                                          Layout = new Layout2RawLayoutAdapter(new PatternLayout("%logger"))
                                      });

            appender.AddParameter(new AdoNetAppenderParameter
                                      {
                                          ParameterName = "@message",
                                          DbType = DbType.String,
                                          Size = -1,
                                          Layout = new Layout2RawLayoutAdapter(new PatternLayout("%message"))
                                      });

            appender.AddParameter(new AdoNetAppenderParameter
                                      {
                                          ParameterName = "@exception",
                                          DbType = DbType.String,
                                          Size = -1,
                                          Layout = new Layout2RawLayoutAdapter(new PatternLayout("%exception"))
                                      });

            appender.ActivateOptions();

            return appender;
        }
예제 #3
0
        private static AdoNetAppender GenerateAdoNetAppender()
        {
            AdoNetAppender target = new AdoNetAppender();

            target.ConnectionString = ConfigurationManager.ConnectionStrings["RecFinLoggerConnString"].ConnectionString;
            target.CommandText = ConfigurationManager.AppSettings["RecFinLoggerCommandText"];
            target.CommandType = System.Data.CommandType.StoredProcedure;

            target.AddParameter(GetDateParam("@logdate"));
            target.AddParameter(GetPatternParam("@logger", "%log", 225));
            target.AddParameter(GetPatternParam("@level", "%level", 50));
            target.AddParameter(GetPatternParam("@message", "%message", 4000));
            //target.AddParameter(GetPatternParam("@fix", "%fix", 50));
            target.AddParameter(GetExceptionParam("@exception", 4000));

            return target;
        }
예제 #4
0
            public static void LoadADONetAppender()
            {
                Hierarchy hier = LogManager.GetLoggerRepository() as log4net.Repository.Hierarchy.Hierarchy;

                if (hier != null)
                {
                    log4net.Appender.AdoNetAppender appender = new log4net.Appender.AdoNetAppender();
                    appender.Name             = "AdoNetAppender";
                    appender.CommandType      = CommandType.Text;
                    appender.BufferSize       = 1;
                    appender.ConnectionType   = "System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
                    appender.ConnectionString = _ConnectionString;
                    appender.CommandText      = @"INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)";
                    appender.AddParameter(new AdoNetAppenderParameter {
                        ParameterName = "@log_date", DbType = System.Data.DbType.DateTime, Layout = new log4net.Layout.RawTimeStampLayout()
                    });
                    appender.AddParameter(new AdoNetAppenderParameter {
                        ParameterName = "@thread", DbType = System.Data.DbType.String, Size = 255, Layout = new Layout2RawLayoutAdapter(new PatternLayout("%thread"))
                    });
                    appender.AddParameter(new AdoNetAppenderParameter {
                        ParameterName = "@log_level", DbType = System.Data.DbType.String, Size = 50, Layout = new Layout2RawLayoutAdapter(new PatternLayout("%level"))
                    });
                    appender.AddParameter(new AdoNetAppenderParameter {
                        ParameterName = "@logger", DbType = System.Data.DbType.String, Size = 255, Layout = new Layout2RawLayoutAdapter(new PatternLayout("%logger"))
                    });
                    appender.AddParameter(new AdoNetAppenderParameter {
                        ParameterName = "@message", DbType = System.Data.DbType.String, Size = 4000, Layout = new Layout2RawLayoutAdapter(new PatternLayout("%message"))
                    });
                    appender.AddParameter(new AdoNetAppenderParameter {
                        ParameterName = "@exception", DbType = System.Data.DbType.String, Size = 4000, Layout = new Layout2RawLayoutAdapter(new ExceptionLayout())
                    });
                    appender.ActivateOptions();
                    BasicConfigurator.Configure(appender);
                }
            }
예제 #5
0
 private static void AdoNetAppenderProgrammaticConfiguration()
 {
     var adoNetAppender = new AdoNetAppender
     {
         ConnectionType = typeof(SqlConnection).AssemblyQualifiedName,
         ConnectionString = ConfigurationManager.ConnectionStrings["CritechRssStorage"].ConnectionString,
         BufferSize = 1,
         CommandText = "INSERT INTO Logs(Date, Thread, Level, Logger, Message, Exception) VALUES(@Date, @Thread, @Level, @Logger, @Message, @Exception)"
     };
     adoNetAppender.AddParameter(new AdoNetAppenderParameter
     {
         ParameterName = "@Date",
         DbType = DbType.DateTime,
         Layout = new RawTimeStampLayout()
     });
     adoNetAppender.AddParameter(new AdoNetAppenderParameter
     {
         ParameterName = "@Thread",
         DbType = DbType.String,
         Size = 255,
         Layout = new Layout2RawLayoutAdapter(new PatternLayout("%thread"))
     });
     adoNetAppender.AddParameter(new AdoNetAppenderParameter
     {
         ParameterName = "@Level",
         DbType = DbType.String,
         Size = 50,
         Layout = new Layout2RawLayoutAdapter(new PatternLayout("%level"))
     });
     adoNetAppender.AddParameter(new AdoNetAppenderParameter
     {
         ParameterName = "@Logger",
         DbType = DbType.String,
         Size = 255,
         Layout = new Layout2RawLayoutAdapter(new PatternLayout("%logger"))
     });
     adoNetAppender.AddParameter(new AdoNetAppenderParameter
     {
         ParameterName = "@Message",
         DbType = DbType.String,
         Size = 4000,
         Layout = new Layout2RawLayoutAdapter(new PatternLayout("%message"))
     });
     adoNetAppender.AddParameter(new AdoNetAppenderParameter
     {
         ParameterName = "@Exception",
         DbType = DbType.String,
         Size = 4000,
         Layout = new Layout2RawLayoutAdapter(new ExceptionLayout())
     });
     adoNetAppender.ActivateOptions();
     var hierarchy = (Hierarchy)LogManager.GetRepository();
     hierarchy.Root.AddAppender(adoNetAppender);
 }
        public void NullPropertyProgmaticConfig()
        {
            AdoNetAppenderParameter productIdParam = new AdoNetAppenderParameter();
            productIdParam.ParameterName = "@productId";
            productIdParam.DbType = DbType.String;
            productIdParam.Size = 50;
            RawPropertyLayout rawPropertyLayout = new RawPropertyLayout();
            rawPropertyLayout.Key = "ProductId";
            productIdParam.Layout = rawPropertyLayout;

            AdoNetAppender appender = new AdoNetAppender();
            appender.ConnectionType = typeof(Log4NetConnection).FullName;
            appender.BufferSize = -1;
            appender.CommandText = "INSERT INTO Log ([productId]) VALUES (@productId)";
            appender.AddParameter(productIdParam);
            appender.ActivateOptions();

            ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
            BasicConfigurator.Configure(rep, appender);
            ILog log = LogManager.GetLogger(rep.Name, "NullPropertyProgmaticConfig");

            log.Debug("Message");
            IDbCommand command = Log4NetCommand.MostRecentInstance;
            IDbDataParameter param = (IDbDataParameter)command.Parameters["@productId"];
            Assert.AreNotEqual(SystemInfo.NullText, param.Value);
            Assert.AreEqual(DBNull.Value, param.Value);
        }
        private static IAppender GetAdoAppender(IConfigManagerHelper config)
        {
            var connectionString = config.GetConnectionString("OneHydraLog");
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new Exception("A connection string to the log database is required.  Please add the connection string by the name OneHydraLog to the config and make sure the connection string points to a database with the expected OneSearchLog table.");
            }
            var adoAppender = new AdoNetAppender
            {
                Name = "ADONetAppender",
                BufferSize = 1,
                ConnectionType =
                    "System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
                ConnectionString = connectionString,
                CommandText =
                    "INSERT INTO [OneSearchLog] ([Date],[Thread],[Level],[Logger],[Message],[Exception], [MachineName]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception, @machineName)",
                CommandType = CommandType.Text
            };

            //<conversionPattern value="%property{log4net:HostName}" />

            var parameter = new AdoNetAppenderParameter { ParameterName = "@log_date", DbType = DbType.DateTime };
            var patternLayout = new PatternLayout { ConversionPattern = "%date{MM/dd/yyyy HH:mm:ss}" };
            patternLayout.ActivateOptions();
            parameter.Layout = new Layout2RawLayoutAdapter(patternLayout);
            adoAppender.AddParameter(parameter);

            parameter = new AdoNetAppenderParameter { ParameterName = "@thread", DbType = DbType.String, Size = 255 };
            patternLayout = new PatternLayout { ConversionPattern = "%thread" };
            patternLayout.ActivateOptions();
            parameter.Layout = new Layout2RawLayoutAdapter(patternLayout);
            adoAppender.AddParameter(parameter);

            parameter = new AdoNetAppenderParameter { ParameterName = "@log_level", DbType = DbType.String, Size = 50 };
            patternLayout = new PatternLayout { ConversionPattern = "%level" };
            patternLayout.ActivateOptions();
            parameter.Layout = new Layout2RawLayoutAdapter(patternLayout);
            adoAppender.AddParameter(parameter);

            parameter = new AdoNetAppenderParameter { ParameterName = "@logger", DbType = DbType.String, Size = 255 };
            patternLayout = new PatternLayout { ConversionPattern = "%logger" };
            patternLayout.ActivateOptions();
            parameter.Layout = new Layout2RawLayoutAdapter(patternLayout);
            adoAppender.AddParameter(parameter);

            parameter = new AdoNetAppenderParameter { ParameterName = "@message", DbType = DbType.String, Size = 200000000 };
            patternLayout = new PatternLayout { ConversionPattern = "%message" };
            patternLayout.ActivateOptions();
            parameter.Layout = new Layout2RawLayoutAdapter(patternLayout);
            adoAppender.AddParameter(parameter);

            parameter = new AdoNetAppenderParameter { ParameterName = "@machineName", DbType = DbType.String, Size = 255 };
            patternLayout = new PatternLayout { ConversionPattern = "%property{machineName}" };
            patternLayout.ActivateOptions();
            parameter.Layout = new Layout2RawLayoutAdapter(patternLayout);
            adoAppender.AddParameter(parameter);

            parameter = new AdoNetAppenderParameter { ParameterName = "@exception", DbType = DbType.String, Size = 200000000 };
            patternLayout = new PatternLayout { ConversionPattern = "%property{fullException}" };
            patternLayout.ActivateOptions();
            parameter.Layout = new Layout2RawLayoutAdapter(patternLayout);
            //var exceptionLayout = new ExceptionLayout(){IgnoresException = true};
            //exceptionLayout.ActivateOptions();
            //parameter.Layout = new Layout2RawLayoutAdapter(exceptionLayout);
            adoAppender.AddParameter(parameter);

            adoAppender.ActivateOptions();
            return adoAppender;
        }
        /// <summary>
        /// Creates a database appender
        /// </summary>
        /// <param name="ConnStr">Database connection string</param>
        /// <param name="ModuleName">Module name used by logger</param>
        /// <returns>ADONet database appender</returns>
        public static AdoNetAppender CreateDbAppender(string ConnStr, string ModuleName)
        {
            var ReturnAppender = new AdoNetAppender
            {
                BufferSize = 1,
                ConnectionType =
                    "System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
                ConnectionString = ConnStr,
                CommandType = CommandType.StoredProcedure,
                CommandText = "PostLogEntry"
            };

            //Type parameter
            var TypeParam = new AdoNetAppenderParameter
            {
                ParameterName = "@type",
                DbType = DbType.String,
                Size = 50,
                Layout = CreateLayout("%level")
            };
            ReturnAppender.AddParameter(TypeParam);

            //Message parameter
            var MsgParam = new AdoNetAppenderParameter
            {
                ParameterName = "@message",
                DbType = DbType.String,
                Size = 4000,
                Layout = CreateLayout("%message")
            };
            ReturnAppender.AddParameter(MsgParam);

            //PostedBy parameter
            var PostByParam = new AdoNetAppenderParameter
            {
                ParameterName = "@postedBy",
                DbType = DbType.String,
                Size = 128,
                Layout = CreateLayout(ModuleName)
            };
            ReturnAppender.AddParameter(PostByParam);

            ReturnAppender.ActivateOptions();

            return ReturnAppender;
        }
예제 #9
0
        private IAppender GetAdoLogger(ILoggerRepository repository)
        {
            /*
             * IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Log]') AND type in (N'U'))
             * BEGIN
             * CREATE TABLE [dbo].[Log4NetLog](
             * [Id] [int] IDENTITY(1,1) NOT NULL,
             * [Date] [datetime] NOT NULL,
             * [AppID] [varchar(50)] NULL,
             * [Thread] [varchar](255) NULL,
             * [Level] [varchar](50) NULL,
             * [Logger] [varchar](255) NULL,
             * [Message] [varchar](4000) NULL,
             * [Exception] [varchar](4000) NULL,
             * PRIMARY KEY CLUSTERED
             * (
             * [Id] ASC
             * )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
             * ) ON [PRIMARY]
             */
            //  LoadFileAppender();

            log4net.Repository.Hierarchy.Hierarchy hier =
                repository as log4net.Repository.Hierarchy.Hierarchy;
            if (hier != null)
            {
                var    concollection     = this.DbConnectionstring;// ConfigurationManager.ConnectionStrings["Log4NetDbString"];
                string _ConnectionString = "";
                if (concollection != null)
                {
                    //_ConnectionString = concollection.ConnectionString;
                    //_Provider = concollection.ProviderName;
                    //    if (string.IsNullOrEmpty(_ConnectionString))
                    //        _ConnectionString = "server =10.97.178.251; uid=sa; database=cnblogs; password=niejunhua; Connect Timeout=30; Connection Lifetime =120;  Pooling=true; Max Pool Size=10000; Min Pool Size=5;";
                    _ConnectionString = this.DbConnectionstring;
                }
                if (string.IsNullOrEmpty(_ConnectionString))
                {
                    return(null);
                }
                log4net.Appender.AdoNetAppender adoAppender = new log4net.Appender.AdoNetAppender();
                adoAppender.Name             = "AdoNetAppender";
                adoAppender.CommandType      = CommandType.Text;
                adoAppender.BufferSize       = 1;
                adoAppender.ConnectionType   = "System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
                adoAppender.ConnectionString = _ConnectionString;
                StringBuilder sb = new StringBuilder("INSERT INTO [" + LogTableName + "] (");
                sb.Append("[Date],[Thread],[Level],[Logger],[Message],[Exception]");
                sb.Append(",[AppId]");
                sb.Append(",[ModuleName]");
                sb.Append(",[LogType],[UserID],[OperationName],[Code],[ClientIP],[Uri],[Msg],[ServerName]");
                sb.Append(",[Title],[InputBody],[OutputBody],[InvokeTime],[ElapsedTimes],[AppDomain]");
                //sb.Append("");
                sb.Append(")values(");
                sb.Append("@log_date,@thread,@log_level,@logger,@message,@exception");
                sb.Append(",@AppId");
                sb.Append(",@ModuleName");
                sb.Append(",@LogType,@UserID,@OperationName,@Code,@ClientIP,@Uri,@Msg,@ServerName");
                sb.Append(",@Title,@InputBody,@OutputBody,@InvokeTime,@ElapsedTimes,@AppDomain");

                //sb.Append("");
                sb.Append(")");
                adoAppender.CommandText = sb.ToString();
                //  adoAppender.CommandText = @"INSERT INTO Log4NetLog ([Date],[Thread],[AppID],[Level],[Logger],[Message],[Exception],ht1,ht2) VALUES (@log_date, @thread,'" + appid + "', @log_level, @logger, @message, @exception,@ht1,@ht2)";

                adoAppender.AddParameter(new AdoNetAppenderParameter {
                    ParameterName = "@log_date", DbType = System.Data.DbType.DateTime, Layout = new log4net.Layout.RawTimeStampLayout()
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter {
                    ParameterName = "@thread", DbType = System.Data.DbType.String, Size = 255, Layout = new Layout2RawLayoutAdapter(new PatternLayout("%thread"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter {
                    ParameterName = "@log_level", DbType = System.Data.DbType.String, Size = 50, Layout = new Layout2RawLayoutAdapter(new PatternLayout("%level"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter {
                    ParameterName = "@logger", DbType = System.Data.DbType.String, Size = 255, Layout = new Layout2RawLayoutAdapter(new PatternLayout("%logger"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter {
                    ParameterName = "@message", DbType = System.Data.DbType.String, Size = 4000, Layout = new Layout2RawLayoutAdapter(new PatternLayout(""))
                });                                                                                                                                                                                                //%message
                adoAppender.AddParameter(new AdoNetAppenderParameter {
                    ParameterName = "@exception", DbType = System.Data.DbType.String, Size = 4000, Layout = new Layout2RawLayoutAdapter(new ExceptionLayout())
                });

                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@AppId",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{AppId}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@ModuleName",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{ModuleName}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@LogType",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{LogType}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@UserID",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{UserID}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@OperationName",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{OperationName}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@Code",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{Code}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@ClientIP",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{ClientIP}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@Uri",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{Uri}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@Msg",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{Msg}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@ServerName",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{ServerName}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@Title",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{Title}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@InputBody",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{InputBody}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@OutputBody",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{OutputBody}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@InvokeTime",
                    DbType        = System.Data.DbType.DateTime,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{InvokeTime}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@ElapsedTimes",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{ElapsedTimes}"))
                });
                adoAppender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@AppDomain",
                    DbType        = System.Data.DbType.String,
                    Size          = 4000,
                    Layout        = new Layout2RawLayoutAdapter(new HCustomLayout("%custom{AppDomain}"))
                });

                adoAppender.ActivateOptions();
                //BasicConfigurator.Configure(adoAppender);
                return(adoAppender);
            }
            return(null);
        }
예제 #10
0
        private static void LoadADONetAppender()
        {
            ICfg cfg = CfgFactory.Create();
            ICrypto crypto = CryptoFactory.Create();

            log4net.Repository.Hierarchy.Hierarchy hier = log4net.LogManager.GetLoggerRepository() as log4net.Repository.Hierarchy.Hierarchy;
            log4net.Appender.AdoNetAppender adoAppender = new log4net.Appender.AdoNetAppender();
            adoAppender.Name="ADONetAppender";
            adoAppender.CommandType = System.Data.CommandType.Text;
            adoAppender.BufferSize = 50;
            adoAppender.ConnectionType = "System.Data.SQLite.SQLiteConnection, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139";
            adoAppender.ConnectionString = crypto.Decrypt(cfg.Properties["logging.ConnectionString"], CryptoMode.DES);
            adoAppender.CommandText = @"insert into [SysAppLog] ([Date],[Level],[Message],[Exception]) Values(@Date,@Level,@Message,@Exception);";
            adoAppender.AddParameter(new AdoNetAppenderParameter { ParameterName = "@Date", DbType = DbType.DateTime, Layout = new RawTimeStampLayout() });
            adoAppender.AddParameter(new AdoNetAppenderParameter { ParameterName = "@Level", DbType = DbType.String, Layout = new Layout2RawLayoutAdapter(new PatternLayout("%level")) });
            adoAppender.AddParameter(new AdoNetAppenderParameter { ParameterName = "@Message", DbType = DbType.String, Layout = new Layout2RawLayoutAdapter(new PatternLayout("%message")) });
            adoAppender.AddParameter(new AdoNetAppenderParameter { ParameterName = "@Exception", DbType = DbType.String, Layout = new Layout2RawLayoutAdapter(new PatternLayout("%exception")) });
            adoAppender.ActivateOptions();
            BasicConfigurator.Configure(adoAppender);
        }