Example #1
0
 public static void AddDateTimeParameterToAppender(this log4net.Appender.AdoNetAppender appender, string paramName)
 {
     AdoNetAppenderParameter param = new AdoNetAppenderParameter();
     param.ParameterName = paramName;
     param.DbType = System.Data.DbType.DateTime;
     param.Layout = new RawUtcTimeStampLayout();
     appender.AddParameter(param);
 }
Example #2
0
 public static void AddStringParameterToAppender(this log4net.Appender.AdoNetAppender appender, string paramName, int size, string conversionPattern)
 {
     AdoNetAppenderParameter param = new AdoNetAppenderParameter();
     param.ParameterName = paramName;
     param.DbType = System.Data.DbType.String;
     param.Size = size;
     param.Layout = new Layout2RawLayoutAdapter(new PatternLayout(conversionPattern));
     appender.AddParameter(param);
 }
Example #3
0
 public static void AddErrorParameterToAppender(this log4net.Appender.AdoNetAppender appender, string paramName, int size)
 {
     AdoNetAppenderParameter param = new AdoNetAppenderParameter();
     param.ParameterName = paramName;
     param.DbType = System.Data.DbType.String;
     param.Size = size;
     param.Layout = new Layout2RawLayoutAdapter(new ExceptionLayout());
     appender.AddParameter(param);
 }
        private static AdoNetAppenderParameter GetDateParam(string ParamName)
        {
            AdoNetAppenderParameter param = new AdoNetAppenderParameter();
            param.ParameterName = ParamName;
            param.DbType = System.Data.DbType.DateTime;
            param.Layout = new RawTimeStampLayout();

            return param;
        }
        public RollingEmbeddedDatabaseAppender()
        {
            directory = Environment.CurrentDirectory;
            if(HttpContext.Current!=null)
            {
                directory = AppDomain.CurrentDomain.BaseDirectory;
                //this is apperantly required in order to work correctly under ASP.Net
                AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
            }
            m_usePreparedCommand = false;
            ReconnectOnError = true;
            CommandText =
                @"INSERT INTO Logs (Date, Thread, Level, Logger, Message, Exception)
                        VALUES (@Date, @Thread, @Level, @Logger, @Message, @Exception)";

            AdoNetAppenderParameter date = new AdoNetAppenderParameter();
            date.DbType = DbType.DateTime;
            date.ParameterName = "@Date";
            date.Layout = new RawTimeStampLayout();
            AddParameter(date);

            AdoNetAppenderParameter thread = new AdoNetAppenderParameter();
            thread.DbType = DbType.String;
            thread.ParameterName = "@Thread";
            thread.Size = 255;
            thread.Layout = new Layout2RawLayoutAdapter(new PatternLayout("%thread"));
            AddParameter(thread);

            AdoNetAppenderParameter level = new AdoNetAppenderParameter();
            level.DbType = DbType.String;
            level.ParameterName = "@Level";
            level.Size = 50;
            level.Layout = new Layout2RawLayoutAdapter(new PatternLayout("%level"));
            AddParameter(level);

            AdoNetAppenderParameter logger = new AdoNetAppenderParameter();
            logger.DbType = DbType.String;
            logger.ParameterName = "@Logger";
            logger.Size = 512;
            logger.Layout = new Layout2RawLayoutAdapter(new PatternLayout("%logger"));
            AddParameter(logger);

            AdoNetAppenderParameter message = new AdoNetAppenderParameter();
            message.DbType = DbType.String;
            message.ParameterName = "@Message";
            message.Size = 2000;
            message.Layout = new Layout2RawLayoutAdapter(new PatternLayout("%message"));
            AddParameter(message);

            AdoNetAppenderParameter exception = new AdoNetAppenderParameter();
            exception.DbType = DbType.String;
            exception.ParameterName = "@Exception";
            exception.Size = 4000;
            exception.Layout = new Layout2RawLayoutAdapter(new PatternLayout("%exception"));
            AddParameter(exception);
        }
        private static AdoNetAppenderParameter GetPatternParam(string ParamName, string Pattern, int Size)
        {
            AdoNetAppenderParameter param = new AdoNetAppenderParameter();
            param.ParameterName = ParamName;
            param.DbType = System.Data.DbType.String;
            param.Size = Size;
            param.Layout = new Layout2RawLayoutAdapter(new PatternLayout(Pattern));

            return param;
        }
Example #7
0
		/// <summary>
		/// Adds a parameter to the command.
		/// </summary>
		/// <param name="parameter">The parameter to add to the command.</param>
		/// <remarks>
		/// <para>
		/// Adds a parameter to the ordered list of command parameters.
		/// </para>
		/// </remarks>
		public void AddParameter(AdoNetAppenderParameter parameter)
		{
			m_parameters.Add(parameter);
		}
        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;
        }
 private KeyValuePair<string, object> FormatParameter(AdoNetAppenderParameter parameter, LoggingEvent loggingEvent)
 {
     string key = parameter.ParameterName;
     object value = parameter.Layout.Format(loggingEvent);
     return new KeyValuePair<string, object>(key, (value as string).NullOrEmpty() ? null : value);
 }
        /// <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;
        }
 /// <summary>
 /// Adds a parameter to the command.
 /// </summary>
 /// <param name="parameter">The parameter to add to the command.</param>
 /// <remarks>
 /// <para>
 /// Adds a parameter to the ordered list of command parameters.
 /// </para>
 /// </remarks>
 public void AddParameter(AdoNetAppenderParameter parameter)
 {
     m_parameters.Add(parameter);
 }