コード例 #1
1
ファイル: LogConfig.cs プロジェクト: zidanfei/Dot.Utility
        /// <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
ファイル: LogHelper.cs プロジェクト: aa1356889/LOG4NETDEMO
            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);
                }
            }
コード例 #3
0
ファイル: Log4NetConfiguration.cs プロジェクト: dwick/Me
        /// <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;
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: gimmi/randomhacking
 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);
 }
コード例 #5
0
        public void NoBufferingTest()
        {
            ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());

            AdoNetAppender adoNetAppender = new AdoNetAppender();
            adoNetAppender.BufferSize = -1;
            adoNetAppender.ConnectionType = "log4net.Tests.Appender.AdoNet.Log4NetConnection";
            adoNetAppender.ActivateOptions();

            BasicConfigurator.Configure(rep, adoNetAppender);

            ILog log = LogManager.GetLogger(rep.Name, "NoBufferingTest");
            log.Debug("Message");
            Assert.AreEqual(1, Log4NetCommand.MostRecentInstance.ExecuteNonQueryCount);
        }
コード例 #6
0
ファイル: LoggingManager.cs プロジェクト: KamilZet/BugNet
        /// <summary>
        /// Configures the ADO net appender.
        /// </summary>
        private static void ConfigureAdoNetAppender()
        {
            // Get the Hierarchy object that organizes the loggers
            log4net.Repository.Hierarchy.Hierarchy hier =
                log4net.LogManager.GetRepository() as log4net.Repository.Hierarchy.Hierarchy;

            if (hier != null)
            {
                //get ADONetAppender
                log4net.Appender.AdoNetAppender adoAppender =
                    (log4net.Appender.AdoNetAppender)hier.Root.GetAppender("AdoNetAppender");

                if (adoAppender != null)
                {
                    adoAppender.ConnectionString = ConfigurationManager.ConnectionStrings["BugNET"].ConnectionString;
                    adoAppender.ActivateOptions(); //refresh settings of appender
                }
            }
        }
コード例 #7
0
ファイル: TestClass.cs プロジェクト: marcin-sitko/Log4NetBug
 public static IAppender CreateAdoNetAppender(string cs)
 {
     AdoNetAppender appender = new AdoNetAppender();
     appender.Name = "AdoNetAppender";
     appender.BufferSize = 1;
     appender.ConnectionType = "System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
     appender.ConnectionString = cs;
     appender.CommandText = @"INSERT INTO LogNet
     ([DateUtc],[Thread],[Level],[Logger],[User],[Message],[Exception]) VALUES
     (@date,@thread,@level,@logger,@user,@message,@exception)";
     AddDateTimeParameterToAppender(appender, "date");
     AddStringParameterToAppender(appender, "thread", 20, "%thread");
     AddStringParameterToAppender(appender, "level", 10, "%level");
     AddStringParameterToAppender(appender, "logger", 200, "%logger");
     AddStringParameterToAppender(appender, "user", 20, "%property{user}");
     AddStringParameterToAppender(appender, "message", 1000, "%message%newline%property");
     AddErrorParameterToAppender(appender, "exception", 4000);
     appender.ActivateOptions();
     return appender;
 }
コード例 #8
0
        /// <summary>
        /// Configure the log4net
        /// </summary>
        ///  <example>
        /// An example of a logger name = MyApplication
        /// /// </example>
        public static void Configure(string logger, string configFile, LogType type, string appernder)
        {
            logType = type;
            //Gets the logger object
            log = LogManager.GetLogger(logger);

            if (configFile != null && configFile.Length != 0)
            {
                FileInfo fInfo = null;
                try
                {
                    fInfo = new FileInfo(System.Web.HttpRuntime.AppDomainAppPath + @"bin\" + configFile);
                }
                catch
                {
                    fInfo = new FileInfo(@".\" + configFile);
                }

                //Configure the log4net by reading config file
                log4net.Config.XmlConfigurator.Configure(fInfo);
            }
            else
            {
                log4net.Config.XmlConfigurator.Configure();
            }

            //if there is AdoNetAppender, decrypt the connection
            log4net.Repository.Hierarchy.Hierarchy h = LogManager.GetRepository() as log4net.Repository.Hierarchy.Hierarchy;
            if (h != null)
            {
                log4net.Appender.AdoNetAppender adoAppender = (log4net.Appender.AdoNetAppender)h.GetLogger("logger.database", h.LoggerFactory).GetAppender(appernder);
                if (adoAppender != null)
                {
                    EncryptUtility de = new EncryptUtility(EncryptUtility.SymmProvEnum.DES);
                    adoAppender.ConnectionString = de.Decrypting(adoAppender.ConnectionString, ENCRYPTION_KEY);
                    adoAppender.ActivateOptions();
                }
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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;
        }
コード例 #11
0
        /// <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;
        }
コード例 #12
0
ファイル: HLogHelper.cs プロジェクト: popotans/HJN.Utility
        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);
        }
コード例 #13
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);
        }