当前位置: 首页>>代码示例>>C#>>正文


C# PatternLayout.ActivateOptions方法代码示例

本文整理汇总了C#中log4net.Layout.PatternLayout.ActivateOptions方法的典型用法代码示例。如果您正苦于以下问题:C# PatternLayout.ActivateOptions方法的具体用法?C# PatternLayout.ActivateOptions怎么用?C# PatternLayout.ActivateOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在log4net.Layout.PatternLayout的用法示例。


在下文中一共展示了PatternLayout.ActivateOptions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Configure

        public static void Configure()
        {
            var hierarchy = (Hierarchy)LogManager.GetRepository();
            hierarchy.Root.RemoveAllAppenders();

            // see http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html

            var layout = new PatternLayout
            {
                ConversionPattern = "%date{dd-MMM-yyyy HH:mm:ss}  %-5level  %message%n%exception%n"
            };

            var fileAppender = new RollingFileAppender
            {
                Layout = layout,
                AppendToFile = true,
                File = "log.txt",
                LockingModel = new FileAppender.MinimalLock(),
            };

            var consoleAppender = new ConsoleAppender
            {
                Layout = layout,
            };

            layout.ActivateOptions();

            fileAppender.ActivateOptions();
            log4net.Config.BasicConfigurator.Configure(fileAppender);

            consoleAppender.ActivateOptions();
            log4net.Config.BasicConfigurator.Configure(consoleAppender);
        }
开发者ID:sumothecat,项目名称:Pushbaby,代码行数:33,代码来源:Log4NetConfiguration.cs

示例2: CrearAppenderFichero

        /// <summary>
        /// Contiene la logica para crear un appender FICHERO
        /// </summary>
        /// <param name="nombreAppender">Nombre del appender</param>
        /// <param name="nombreFichero">Nombre del fichero</param>
        /// <param name="patronConversion"> Si se deja a null el valor por defecto es %d [%t] %-5p %c [%x] - %m%n </param>
        /// <returns>Retorna el appender creado</returns>
        public static IAppender CrearAppenderFichero(string nombreAppender, string nombreFichero, string patronConversion)
        {
            var appender = new FileAppender
            {
                Name = nombreAppender,
                File = nombreFichero,
                AppendToFile = true
            };

            var patronConversionAux = "%d [%t] %-5p %c [%x] - %m%n";
            if(patronConversion != null && !patronConversion.Equals(string.Empty))
            {
                patronConversionAux = patronConversion;
            }

            var layout = new PatternLayout
            {
                ConversionPattern = patronConversionAux
            };
            layout.ActivateOptions();

            appender.Layout = layout;
            appender.ActivateOptions();

            return appender;
        }
开发者ID:domitienda,项目名称:DomiLibrary,代码行数:33,代码来源:FileAppenderHelper.cs

示例3: RegisterTypes

        public static void RegisterTypes(IUnityContainer container)
        {
            var hierarchy = (Hierarchy)LogManager.GetRepository();
            hierarchy.Root.RemoveAllAppenders();

            hierarchy.Root.Level = Level.Debug;
            hierarchy.RaiseConfigurationChanged(EventArgs.Empty);

            FileAppender fileAppender = new RollingFileAppender();
            fileAppender.AppendToFile = true;
            fileAppender.LockingModel = new FileAppender.MinimalLock();
            fileAppender.File = HttpContext.Current.Server.MapPath("~/TestHarness1.log.txt");
            var patternLayout = new PatternLayout { ConversionPattern = "%d [%2%t] %-5p [%-10c]   %m%n%n" };
            patternLayout.ActivateOptions();

            fileAppender.Layout = patternLayout;
            fileAppender.ActivateOptions();

            BasicConfigurator.Configure(fileAppender);

            var logger = LogManager.GetLogger(typeof(IServiceBus));

            container.RegisterInstance<ILog>(logger, new ContainerControlledLifetimeManager());

            var ftpClient = new FtpQueueClient();
            ftpClient.ConnectAsync(new Uri("ftp://ftp.jdibble.co.uk/site1/Personal/service-bus-ftp/queue"), new NetworkCredential("jdibble-001", "jli798ik")).Wait();

            container.RegisterInstance<IFtpQueueClient>(ftpClient, new ContainerControlledLifetimeManager());

            container.RegisterType<IQueueManager, FtpQueueManager>(new ContainerControlledLifetimeManager());

            container.RegisterType<SharedMessageHandler>();

            var messageDictionary = new MessageTypeDictionary
                                    {
                                        { ServiceBus.Messaging.MessageExtensions.MessageTypeSignature<SharedMessage>(), typeof(SharedMessage) },
                                        { ServiceBus.Messaging.MessageExtensions.MessageTypeSignature<NonSharedMessage>(), typeof(NonSharedMessage) },
                                        { ServiceBus.Messaging.MessageExtensions.MessageTypeSignature<SharedEvent>(), typeof(SharedEvent) }
                                    };

            container.RegisterInstance<IMessageSerialiser>(new JsonMessageSerialiser(messageDictionary), new ContainerControlledLifetimeManager());

            var serviceBus =
                ServiceBusBuilder.Configure()
                    .WithLogger(container.Resolve<ILog>())
                    .WithHostAddress(new Uri("http://servicebus-ftp.jdibble.co.uk"))
                    .WithHttpTransport(new JsonMessageSerialiser(messageDictionary))
                    .AsMvcServiceBus(RouteTable.Routes, container.Resolve<IQueueManager>())
                    .Build()
                        .WithMessageHandler(container.Resolve<SharedMessageHandler>())
                        .Subscribe(container.Resolve<SharedEventHandler>())
                        .WithPeerAsync(new Peer(new Uri("http://servicebus-ftp2.jdibble.co.uk"))).Result;

            serviceBus.WithPeerAsync(new Peer(new Uri("http://servicebus.jdibble.co.uk")));
            serviceBus.WithPeerAsync(new Peer(new Uri("http://servicebus2.jdibble.co.uk")));

            container.RegisterInstance(serviceBus, new ContainerControlledLifetimeManager());

            container.RegisterType<ServiceBusHub>(new ContainerControlledLifetimeManager());
        }
开发者ID:dibble-james,项目名称:ServiceBus,代码行数:60,代码来源:Bootstrapper.cs

示例4: Setup

        public static void Setup(string path)
        {
            var hierarchy = (Hierarchy)LogManager.GetRepository();

            var patternLayout = new PatternLayout();
            patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
            // patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
            patternLayout.ActivateOptions();

            var roller = new RollingFileAppender();
            roller.AppendToFile = true;
            roller.File = path;
            roller.Layout = patternLayout;
            roller.MaxSizeRollBackups = 5;
            roller.MaximumFileSize = "2MB";
            roller.RollingStyle = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            var memory = new MemoryAppender();
            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
开发者ID:StefanMihaylov,项目名称:PerforceBackup,代码行数:27,代码来源:Log4netSettings.cs

示例5: Configure

    /// <summary>
    /// Configures the <see cref="FileLogger"/> logger adding the appenders
    /// to the root repository.
    /// </summary>
    public void Configure() {
      // create a new logger into the repository of the current assembly.
      ILoggerRepository root_repository =
        LogManager.GetRepository(Assembly.GetExecutingAssembly());

      Logger nohros_console_logger =
        root_repository.GetLogger("NohrosConsoleLogger") as Logger;

      // create the layout and appender for on error messages.
      PatternLayout layout = new PatternLayout();
      layout.ConversionPattern = layout_pattern_;
      layout.ActivateOptions();

      // create the appender
      ConsoleAppender appender = new ConsoleAppender();
      appender.Name = "NohrosCommonConsoleAppender";
      appender.Layout = layout;
      appender.Target = "Console.Out";
      appender.Threshold = Level.All;
      appender.ActivateOptions();

      nohros_console_logger.Parent.AddAppender(appender);

      root_repository.Configured = true;

      logger = LogManager.GetLogger("NohrosConsoleLogger");
    }
开发者ID:joethinh,项目名称:nohros-must,代码行数:31,代码来源:ConsoleLogger.cs

示例6: CreateLogger

        private void CreateLogger(String name, String conversionPattern)
        {
            // Create Appender
            var nameWDate = name + "_" + _time;
            var path = (_path.Equals(""))
                ? @"Logs\" + _date + @"\" + _time.Replace(':', '_') + @"\" + name + ".log"
                : _path + _date + @"\" + _time.Replace(':', '_') + @"\" + name + ".log";
            var appender = new RollingFileAppender()
            {
                Name = nameWDate,
                File = path,
                AppendToFile = true
            };

            // Create Layout
            var layout = new PatternLayout() {ConversionPattern = conversionPattern};
            layout.ActivateOptions();

            // Apply Layout to Appender
            appender.Layout = layout;
            appender.ActivateOptions();

            // Create Logger
            var logger = LogManager.GetLogger(nameWDate);

            // Apply Appender to Logger
            ((log4net.Repository.Hierarchy.Logger) logger.Logger).AddAppender(appender);

            // Add Logger to Dictionary
            _loggers.Add(name, logger);

            XmlConfigurator.Configure();
        }
开发者ID:dankrasniak,项目名称:Inzynierka,代码行数:33,代码来源:LogIt.cs

示例7: ConfigureLog4Net

    public static void ConfigureLog4Net()
    {
        var layout = new PatternLayout
        {
            ConversionPattern = "%d [%t] %-5p %c [%x] - %m%n"
        };
        layout.ActivateOptions();
        var consoleAppender = new ColoredConsoleAppender
        {
            Threshold = Level.Debug,
            Layout = layout
        };
        consoleAppender.ActivateOptions();
        var appender = new RollingFileAppender
        {
            DatePattern = "yyyy-MM-dd'.txt'",
            RollingStyle = RollingFileAppender.RollingMode.Composite,
            MaxFileSize = 10 * 1024 * 1024,
            MaxSizeRollBackups = 10,
            LockingModel = new FileAppender.MinimalLock(),
            StaticLogFileName = false,
            File =  @"nsb_log_",
            Layout = layout,
            AppendToFile = true,
            Threshold = Level.Debug,
        };
        appender.ActivateOptions();

        BasicConfigurator.Configure(appender, consoleAppender);
    }
开发者ID:nitin-natu,项目名称:NServiceBus.Log4Net,代码行数:30,代码来源:LoggingConfig.cs

示例8: set_file_appender

        public static void set_file_appender(string output_directory)
        {
            if (!already_configured_file_appender)
            {
                already_configured_file_appender = true;

                var layout = new PatternLayout
                {
                    ConversionPattern = "%date [%-5level] - %message%newline"
                };
                layout.ActivateOptions();

                var rollingFileAppender = new RollingFileAppender
                {
                    Name = "roundhouse.changes.log.appender",
                    File = Path.Combine(Path.GetFullPath(output_directory), "roundhouse.changes.log"),
                    Layout = layout,
                    AppendToFile = false
                };
                rollingFileAppender.ActivateOptions();

                var log = LogManager.GetLogger("roundhouse");
                var logger = (log4net.Repository.Hierarchy.Logger)log.Logger;
                logger.AddAppender(rollingFileAppender);
            
                var nhLog = LogManager.GetLogger("NHibernate.SQL");
                var nhLogger = (log4net.Repository.Hierarchy.Logger)nhLog.Logger;
                nhLogger.AddAppender(rollingFileAppender);
            }
        }
开发者ID:Smartrak,项目名称:roundhouse,代码行数:30,代码来源:Log4NetAppender.cs

示例9: Configure

        public void Configure()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
            hierarchy.Root.RemoveAllAppenders(); /*Remove any other appenders*/

            FileAppender fileAppender = new FileAppender();
            fileAppender.AppendToFile = true;
            fileAppender.LockingModel = new FileAppender.MinimalLock();
            fileAppender.File = _locationProvider.GetFilePath();
            PatternLayout pl = new PatternLayout();
            pl.ConversionPattern = "%d [%2%t] %-5p [%-10c]   %m%n%n";
            pl.ActivateOptions();
            fileAppender.Layout = pl;
            fileAppender.ActivateOptions();

            ConsoleAppender consoleAppender = new ConsoleAppender();
            consoleAppender.Layout = pl;
            consoleAppender.ActivateOptions();

            //            log4net.Config.BasicConfigurator.Configure(fileAppender);
            IAppender[] appenders = {fileAppender, consoleAppender};
            log4net.Config.BasicConfigurator.Configure(appenders);
            var log = LogManager.GetLogger(GetType());
            log.Debug("Logging Configured");
        }
开发者ID:SimplyChris,项目名称:LibHipChat,代码行数:25,代码来源:LogConfigurator.cs

示例10: Setup

        public static void Setup(string path)
        {
            // "%d[%2%t] %-5p[%-10c] %m %n"
            var pl = new PatternLayout {ConversionPattern = "%c%m%n"};
            pl.ActivateOptions();

            var fileAppender = new FileAppender
            {
                AppendToFile = true,
                LockingModel = new FileAppender.MinimalLock(),
                File = path,
                Layout = pl
            };
            fileAppender.ActivateOptions();

            var bufferingForwardingAppender = new BufferingForwardingAppender
            {
                Lossy = false,
                Fix = FixFlags.None
            };
            bufferingForwardingAppender.AddAppender(fileAppender);
            bufferingForwardingAppender.ActivateOptions();

            var consoleAppender = new ConsoleAppender {Layout = pl};
            consoleAppender.ActivateOptions();

            var hierarchy = (Hierarchy) LogManager.GetRepository();
            hierarchy.Root.RemoveAllAppenders();
            BasicConfigurator.Configure(hierarchy, bufferingForwardingAppender, consoleAppender);
        }
开发者ID:wwhitehead,项目名称:ProjectFaolan,代码行数:30,代码来源:Logger.cs

示例11: CreateFileAppender

        // Create a new file appender
        public static RollingFileAppender CreateFileAppender(LoggerConfigurationElement element)
        {
            var appender = new RollingFileAppender();
            appender.Name = element.LoggerName;
            appender.File = element.Filename;
            appender.AppendToFile = true;
            appender.RollingStyle = RollingFileAppender.RollingMode.Composite;
            appender.MaximumFileSize = element.MaximumFileSize;
            appender.MaxSizeRollBackups = element.MaxSizeRollBackups;
            appender.PreserveLogFileNameExtension = element.PreserveLogFileNameExtension;
            appender.DatePattern = element.DatePattern;

            var layout = new PatternLayout();
            layout.ConversionPattern = "%message";
            layout.ActivateOptions();

            var filter = new LoggerMatchFilter();
            filter.LoggerToMatch = element.LoggerName;
            filter.ActivateOptions();

            var denyAllFilter = new DenyAllFilter();
            denyAllFilter.ActivateOptions();

            appender.AddFilter(filter);
            appender.AddFilter(denyAllFilter);

            appender.Layout = layout;
            appender.ActivateOptions();

            return appender;
        }
开发者ID:bisand,项目名称:Graviton,代码行数:32,代码来源:LogConfigurator.cs

示例12: InitLog4net

        private static void InitLog4net()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();
            patternLayout.ConversionPattern = "[%date] %-5level [%thread] %property{user} - %message%exception%n";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();
            roller.AppendToFile = true;
            roller.File = @"logs\";
            roller.Layout = patternLayout;
            roller.MaxSizeRollBackups = 100;
            roller.MaximumFileSize = "10MB";
            roller.RollingStyle = RollingFileAppender.RollingMode.Date;
            roller.DatePattern = "yyyyMMdd'.log'";
            roller.StaticLogFileName = false;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;

            log4net.GlobalContext.Properties["user"] = new Log4NetUserNameProvider();
        }
开发者ID:zhh007,项目名称:CKGen,代码行数:25,代码来源:Bootstrap.cs

示例13: Logger

        static Logger()
        {
            var hierarchy = (Hierarchy)LogManager.GetRepository();
            var tracer = new TraceAppender();
            var patternLayout = new PatternLayout {ConversionPattern = LOG_PATTERN};

            patternLayout.ActivateOptions();

            tracer.Layout = patternLayout;
            tracer.ActivateOptions();
            hierarchy.Root.AddAppender(tracer);

            var roller = new RollingFileAppender
                             {
                                 Layout = patternLayout,
                                 AppendToFile = true,
                                 RollingStyle = RollingFileAppender.RollingMode.Size,
                                 MaxSizeRollBackups = 4,
                                 MaximumFileSize = "10240KB",
                                 StaticLogFileName = true,
                                 File = FilePath + @"\f1speed-log.txt"
                             };
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            hierarchy.Root.Level = Level.Debug;
            hierarchy.Configured = true;
        }
开发者ID:Malyngo,项目名称:DirtRallyWebTelemetry,代码行数:28,代码来源:Logging.cs

示例14: DefaultLogWrapper

        public DefaultLogWrapper(string logname, IConfig config)
        {
            this.logname = logname;

            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
            hierarchy.Clear();

            TraceAppender tracer = new TraceAppender();
            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%t (%-5level) - %m%n";
            patternLayout.ActivateOptions();

            tracer.Layout = patternLayout;
            tracer.ActivateOptions();
            hierarchy.Root.AddAppender(tracer);

            RollingFileAppender roller = new RollingFileAppender();
            roller.Layout = patternLayout;
            roller.AppendToFile = true;
            roller.RollingStyle = RollingFileAppender.RollingMode.Size;
            roller.MaxSizeRollBackups = 4;
            roller.MaximumFileSize = "100KB";
            roller.StaticLogFileName = true;
            roller.File = Path.Combine(config.IndexFolder, "totalrecall-" + this.logname + ".log");
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
        }
开发者ID:riadyb,项目名称:totalrecall,代码行数:31,代码来源:DefaultLogWrapper.cs

示例15: SetPath

        public void SetPath(String path)
        {
            //_writer = new StreamWriter(path);

            //_path = path;
            PatternLayout patternLayout = new PatternLayout
            {
                ConversionPattern = "[%date] - [%logger] - %level  - %message%newline"
            };
            patternLayout.ActivateOptions();

            RollingFileAppender rollingFileAppender = new RollingFileAppender
            {
                File = path,
                Layout = patternLayout,
                MaximumFileSize = "5MB",
                MaxSizeRollBackups = 2,
                PreserveLogFileNameExtension = true,
                RollingStyle = RollingFileAppender.RollingMode.Size,
                LockingModel = new FileAppender.MinimalLock()
            };
            rollingFileAppender.ActivateOptions();

            Hierarchy hierarchy = LogManager.GetRepository() as Hierarchy;
            Logger root = hierarchy.Root;
            root.RemoveAllAppenders();

            root.Level = Level.All;

            BasicConfigurator.Configure(rollingFileAppender);
        }
开发者ID:Ledragon,项目名称:VideoPlayer,代码行数:31,代码来源:LoggingSystemManager.cs


注:本文中的log4net.Layout.PatternLayout.ActivateOptions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。