Beispiel #1
0
        public virtual AppenderConfiguration Merge(AppenderConfiguration default_appender)
        {
            if (string.IsNullOrEmpty(Name))
            {
                Name = default_appender.Name;
            }

            if (string.IsNullOrEmpty(Template))
            {
                Template = default_appender.Template;
            }

            return(this);
        }
Beispiel #2
0
        static void CreateAppender(AppenderConfiguration configuration, log4net.Core.IAppenderAttachable collection)
        {
            if (configuration != null)
            {
                if (!string.IsNullOrEmpty(configuration.Name))
                {
                    if (collection.GetAppender(configuration.Name) == null)
                    {
                        // Create the appender and add it to the loggers collection of appenders.
                        // Create the appender based on the type of configuration.
                        if (configuration is RollingFileAppenderConfiguration)
                        {
                            var rolling_file_configuration = configuration as RollingFileAppenderConfiguration;

                            // If a file name is not provided for the log file then attempt to use the applications name.
                            var rolling_appender = new log4net.Appender.RollingFileAppender
                            {
                                Name = configuration.Name,
                                MaxSizeRollBackups = Convert.ToInt32(rolling_file_configuration.MaxArchivedFiles),
                                MaximumFileSize    = rolling_file_configuration.RollSizeKB,
                                RollingStyle       = log4net.Appender.RollingFileAppender.RollingMode.Size,
                                StaticLogFileName  = true,
                                LockingModel       = new log4net.Appender.RollingFileAppender.MinimalLock(),
                                File = rolling_file_configuration.Path + (string.IsNullOrEmpty(rolling_file_configuration.FileName) ? GetApplicationName() + ".log" : rolling_file_configuration.FileName),
                                PreserveLogFileNameExtension = true,
                                Layout = new log4net.Layout.PatternLayout(rolling_file_configuration.Template),
                            };

                            //rolling_appender.AddFilter(new log4net.Filter.PropertyFilter{ Key="", StringToMatch=""}); //.StringMatchFilter { StringToMatch = category });
                            //rolling_appender.AddFilter(new log4net.Filter.DenyAllFilter());
                            rolling_appender.ActivateOptions();

                            collection.AddAppender(rolling_appender);
                        }
                        else
                        {
                            throw new Exception("Unable to create the appender. " + configuration.GetType().Name + "'s are not supported.");
                        }
                    }
                }
                else
                {
                    throw new Exception("Unable to create the appender. The name property is undefined.");
                }
            }
        }