• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Layout.PatternLayout类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



PatternLayout类属于log4net.Layout命名空间,在下文中一共展示了PatternLayout类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: 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


示例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: Configure

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

      Logger nohros_file_logger =
        root_repository.GetLogger("NohrosFileAppender") as Logger;

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

      FileAppender appender = new FileAppender();
      appender.Name = "NohrosCommonFileAppender";
      appender.File = log_file_path_;
      appender.AppendToFile = true;
      appender.Layout = layout;
      appender.Threshold = Level.All;
      appender.ActivateOptions();

      // add the appender to the root repository
      nohros_file_logger.Parent.AddAppender(appender);

      root_repository.Configured = true;

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


示例5: SimpleTest

		public void SimpleTest()
		{
			container.AddComponent("component1", typeof(SimpleLoggingComponent));
			SimpleLoggingComponent test = container["component1"] as SimpleLoggingComponent;

			test.DoSomething();

			String expectedLogOutput = String.Format("[INFO ] [{0}] - Hello world" + Environment.NewLine, typeof(SimpleLoggingComponent).FullName);
			MemoryAppender memoryAppender = ((Hierarchy)LogManager.GetRepository()).Root.GetAppender("memory") as MemoryAppender;
			TextWriter actualLogOutput = new StringWriter();
			PatternLayout patternLayout = new PatternLayout("[%-5level] [%logger] - %message%newline");
			patternLayout.Format(actualLogOutput, memoryAppender.GetEvents()[0]);

			Assert.AreEqual(expectedLogOutput, actualLogOutput.ToString());

			container.AddComponent("component2", typeof(SmtpServer));
			ISmtpServer smtpServer = container["component2"] as ISmtpServer;

			smtpServer.Start();
			smtpServer.InternalSend("[email protected]", "[email protected]", "We're looking for a few good porgrammars.");
			smtpServer.Stop();

			expectedLogOutput = String.Format("[DEBUG] [Castle.Facilities.Logging.Tests.Classes.SmtpServer] - Stopped" + Environment.NewLine, typeof(SimpleLoggingComponent).FullName);
			memoryAppender = ((Hierarchy)LogManager.GetRepository()).Root.GetAppender("memory") as MemoryAppender;
			actualLogOutput = new StringWriter();
			patternLayout = new PatternLayout("[%-5level] [%logger] - %message%newline");

			Assert.AreEqual(memoryAppender.GetEvents().Length, 4);

			patternLayout.Format(actualLogOutput, memoryAppender.GetEvents()[3]);

			Assert.AreEqual(expectedLogOutput, actualLogOutput.ToString());
		}
开发者ID:AGiorgetti,项目名称:Castle.InversionOfControl,代码行数:33,代码来源:ExtendedLog4NetFacilityTests.cs


示例6: InitLogger

        /// <summary>
        /// Init log4net memoryAppender 
        /// http://dhvik.blogspot.com/2008/08/adding-appender-to-log4net-in-runtime.html
        /// </summary>
        void InitLogger()
        {
            //First create and configure the appender
            this.memoryAppender = new MemoryAppender();
            this.memoryAppender.Name = this.GetType().Name + "MemoryAppender";

            PatternLayout layout = new PatternLayout();
            layout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
            layout.ActivateOptions();
            this.memoryAppender.Layout = layout;

            //Notify the appender on the configuration changes
            this.memoryAppender.ActivateOptions();

            //Get the logger repository hierarchy.
            this.repository = (Hierarchy)LogManager.GetRepository();

            //and add the appender to the root level
            //of the logging hierarchy
            this.repository.Root.AddAppender(memoryAppender);

            //configure the logging at the root.
            //this.repository.Root.Level = Level.Info;

            //mark repository as configured and notify that is has changed.
            this.repository.Configured = true;
            this.repository.RaiseConfigurationChanged(EventArgs.Empty);

            this.msgWriter = new StringWriter();
        }
开发者ID:kleopatra999,项目名称:SuperPutty-1,代码行数:34,代码来源:Log4netDebugLogForm.cs


示例7: 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


示例8: Log4NetConsoleFactory

		public Log4NetConsoleFactory(LogLevel level)
		{
			var hierarchy = (Hierarchy)global::log4net.LogManager.GetRepository();
			hierarchy.Root.RemoveAllAppenders();

			var layout = new PatternLayout { ConversionPattern = "%utcdate{ISO8601} [%thread] %-3level %-8logger{1} - %message%newline" };
			layout.ActivateOptions();

			var appender = new ColoredConsoleAppender
			{
				Layout = layout,
				Threshold = ToLog4NetLevel(level)
			};

			appender.AddMapping(new ColoredConsoleAppender.LevelColors { ForeColor = ColoredConsoleAppender.Colors.HighIntensity, Level = Level.Debug });
			appender.AddMapping(new ColoredConsoleAppender.LevelColors { ForeColor = ColoredConsoleAppender.Colors.Cyan, Level = Level.Info });
			appender.AddMapping(new ColoredConsoleAppender.LevelColors { ForeColor = ColoredConsoleAppender.Colors.White, BackColor = ColoredConsoleAppender.Colors.Yellow, Level = Level.Warn });
			appender.AddMapping(new ColoredConsoleAppender.LevelColors { ForeColor = ColoredConsoleAppender.Colors.White, BackColor = ColoredConsoleAppender.Colors.Red, Level = Level.Error });
			appender.AddMapping(new ColoredConsoleAppender.LevelColors { ForeColor = ColoredConsoleAppender.Colors.White, BackColor = ColoredConsoleAppender.Colors.Red, Level = Level.Fatal });

			appender.ActivateOptions();

			hierarchy.Root.AddAppender(appender);
			hierarchy.Configured = true;
		}
开发者ID:itzing,项目名称:Detrack-.NET-API,代码行数:25,代码来源:Log4NetConsoleFactory.cs


示例9: SetupLoggers

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

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

            var fileAppender = new RollingFileAppender
                {
                    AppendToFile = false,
                    File =
                        Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Tailviewer",
                                     "Tailviewer.log"),
                    Layout = patternLayout,
                    MaxSizeRollBackups = 20,
                    MaximumFileSize = "1GB",
                    RollingStyle = RollingFileAppender.RollingMode.Size,
                    StaticLogFileName = false
                };
            fileAppender.ActivateOptions();
            hierarchy.Root.AddAppender(fileAppender);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
开发者ID:Kittyfisto,项目名称:Tailviewer,代码行数:28,代码来源:Bootstrapper.cs


示例10: Initialize

        public static void Initialize()
        {
            var hierarchy = (Hierarchy)LogManager.GetRepository();

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

            var roller = new RollingFileAppender();
            roller.AppendToFile = false;
            roller.File = @"Logs\EventLog.txt";
            roller.Layout = patternLayout;
            roller.MaxSizeRollBackups = 5;
            roller.MaximumFileSize = "1GB";
            roller.RollingStyle = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

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

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
开发者ID:jrspinella,项目名称:TestGitExisting,代码行数:26,代码来源:QueueLogger.cs


示例11: Logger

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

            patternLayout.ConversionPattern = LOG_PATTERN;
            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 = "32768KB";
            roller.StaticLogFileName = true;
            roller.File = "log\\Log.log";
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
        }
开发者ID:dionata,项目名称:wfmvc,代码行数:27,代码来源:Logger.cs


示例12: ConfigurePlugin

        protected override void ConfigurePlugin(PluginConfiguration pluginConfiguration, PluginInspector pluginInspector)
        {
            _moduleName = pluginConfiguration.ModuleName;
            BasicConfigurator.Configure();

            var defaultPattern = new PatternLayout { ConversionPattern = LogPattern };
            defaultPattern.ActivateOptions();

            var rollingFileAppender = new RollingFileAppender
            {
                Name = "RollingFileAppender",
                File = "Log/" + _moduleName + ".log",
                AppendToFile = true,
                RollingStyle = RollingFileAppender.RollingMode.Size,
                MaxSizeRollBackups = 15,
                MaximumFileSize = "100MB",
                StaticLogFileName = true,
                Layout = defaultPattern
            };
            rollingFileAppender.ActivateOptions();
            rollingFileAppender.ImmediateFlush = true;
            rollingFileAppender.LockingModel= new FileAppender.InterProcessLock();

            var root = ((Hierarchy)global::log4net.LogManager.GetRepository()).Root;
            root.AddAppender(rollingFileAppender);
            root.Level = Level.Debug;
            root.Repository.Configured = true;
        }
开发者ID:TicketArchitecture,项目名称:EasyArchitecture,代码行数:28,代码来源:Log4NetPlugin.cs


示例13: ConfigureLogging

        public static void ConfigureLogging()
        {
            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 fileAppender = new RollingFileAppender
            {
                DatePattern = "yyyy-MM-dd'.txt'",
                MaxFileSize = 10 * 1024 * 1024,
                MaxSizeRollBackups = 10,
                StaticLogFileName = false,
                File = @"d:\logs\auth",
                Layout = layout,
                AppendToFile = true,
                Threshold = Level.Debug,
            };

            #if DEBUG
            fileAppender.File = @"log_";
            #endif

            fileAppender.ActivateOptions();

            BasicConfigurator.Configure(fileAppender, consoleAppender);
        }
开发者ID:tonyeung,项目名称:IdSvr3AndKentorAuthServices,代码行数:33,代码来源:Program.cs


示例14: SetupLoggers

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

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

            var fileAppender = new RollingFileAppender
            {
                AppendToFile = false,
                File = Constants.InstallationLog,
                Layout = patternLayout,
                MaxSizeRollBackups = 3,
                MaximumFileSize = "1GB",
                RollingStyle = RollingFileAppender.RollingMode.Size,
                StaticLogFileName = false
            };
            fileAppender.ActivateOptions();
            hierarchy.Root.AddAppender(fileAppender);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
开发者ID:Kittyfisto,项目名称:Tailviewer,代码行数:26,代码来源:App.cs


示例15: Setup

        /// <summary>
        /// Setup Log4NET logger.
        /// </summary>
        internal static void Setup()
        {
            var hierarchy = (Hierarchy) LogManager.GetRepository();

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

            var roller = new FileAppender
            {
                AppendToFile = false,
                File = @"AllureLog.txt",
                Layout = patternLayout
            };
            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:michaelmccracken,项目名称:allure-csharp-commons,代码行数:29,代码来源:Logger.cs


示例16: TestThreadSafety

        public void TestThreadSafety()
        {
            ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
            var memoryAppender = new MemoryAppender();
            var patternLayout = new PatternLayout();
            memoryAppender.Layout = patternLayout;
            memoryAppender.ActivateOptions();
            BasicConfigurator.Configure(rep, memoryAppender);

            cThreadsRunning = cThreadsMax;
            var threads = Enumerable.Range(0, cThreadsMax)
                .Select(i => new Thread(LogMessages(rep.Name)))
                .ToList();

            foreach (var thread in threads)
            {
                thread.Start();
            }

            long cEventsRead = 0;
            while (cThreadsRunning > 0)
            {
                var events = memoryAppender.PopAllEvents();
                cEventsRead += events.Length;
            }
            foreach (var thread in threads)
            {
                thread.Join();
            }
	    cEventsRead += memoryAppender.PopAllEvents().Length;
            Assert.AreEqual(cEventsExpected, cEventsRead, "Log events were lost.");
        }
开发者ID:blueskybcl,项目名称:log4net,代码行数:32,代码来源:MemoryAppenderTest.cs


示例17: 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


示例18: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        // gather log4net output with small hack to get results...
        ILoggerRepository repository = LogManager.GetRepository();
        IAppender[] appenders = repository.GetAppenders();
        MemoryAppender appender = null;
        foreach (IAppender a in appenders)
        {
            if (a is MemoryAppender)
            {
                // we found our appender to look results from
                appender = a as MemoryAppender;
                break;
            }
        }

        if (appender != null)
        {
            appender.Clear();
            fulfillmentService.ProcessCustomer(customerEditController.CurrentCustomer.Id);
            LoggingEvent[] events = appender.GetEvents();
            StringWriter stringWriter = new StringWriter();
            PatternLayout layout = new PatternLayout("%date{HH:mm:ss} %-5level %logger{1}: %message<br />");
            foreach (LoggingEvent loggingEvent in events)
            {
                layout.Format(stringWriter, loggingEvent);
            }

            results.Text = stringWriter.ToString();
        }

    }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:32,代码来源:FulfillmentResult.aspx.cs


示例19: Logger

        static Logger()
        {
            const string filename = "log4net.config";
            string basePath = HttpContext.Current != null
                ? AppDomain.CurrentDomain.SetupInformation.PrivateBinPath
                : AppDomain.CurrentDomain.BaseDirectory;
            string configFile = Path.Combine(basePath, filename);
            if (File.Exists(configFile))
            {
                XmlConfigurator.ConfigureAndWatch(new FileInfo(configFile));
                return;
            }

            //默认设置
            RollingFileAppender appender = new RollingFileAppender
            {
                Name = "root",
                File = "logs\\log",
                AppendToFile = true,
                RollingStyle = RollingFileAppender.RollingMode.Composite,
                DatePattern = "yyyyMMdd\".log\"",
                MaxSizeRollBackups = 10
            };

            PatternLayout layout = new PatternLayout("[%d{yyyy-MM-dd HH:mm:ss.fff}] %c.%M %t %n%m%n");
            appender.Layout = layout;
            BasicConfigurator.Configure(appender);
            appender.ActivateOptions();
        }
开发者ID:ciker,项目名称:201509LoginDemo,代码行数:29,代码来源:Logger.cs


示例20: 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类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Appender.StringAppender类代码示例发布时间:2022-05-26
下一篇:
C# Core.LoggingEvent类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap