當前位置: 首頁>>代碼示例>>C#>>正文


C# Config.LoggingRule類代碼示例

本文整理匯總了C#中NLog.Config.LoggingRule的典型用法代碼示例。如果您正苦於以下問題:C# LoggingRule類的具體用法?C# LoggingRule怎麽用?C# LoggingRule使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LoggingRule類屬於NLog.Config命名空間,在下文中一共展示了LoggingRule類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: InitializeLogging

      public static void InitializeLogging() {
         var config = new LoggingConfiguration();
         Target debuggerTarget = new DebuggerTarget() {
            Layout = "${longdate}|${level}|${logger}|${message} ${exception:format=tostring}"
         };
         Target consoleTarget = new ColoredConsoleTarget() {
            Layout = "${longdate}|${level}|${logger}|${message} ${exception:format=tostring}"
         };

#if !DEBUG
         debuggerTarget = new AsyncTargetWrapper(debuggerTarget);
         consoleTarget = new AsyncTargetWrapper(consoleTarget);
#else
         new AsyncTargetWrapper().Wrap(); // Placeholder for optimizing imports
#endif

         config.AddTarget("debugger", debuggerTarget);
         config.AddTarget("console", consoleTarget);

         var debuggerRule = new LoggingRule("*", LogLevel.Trace, debuggerTarget);
         config.LoggingRules.Add(debuggerRule);

         var consoleRule = new LoggingRule("*", LogLevel.Trace, consoleTarget);
         config.LoggingRules.Add(consoleRule);

         LogManager.Configuration = config;
      }
開發者ID:the-dargon-project,項目名稱:Dargon.Zilean,代碼行數:27,代碼來源:ZileanApplicationEgg.cs

示例2: BuildLogger

    public static void BuildLogger()
    {
        var consoleTarget = new ColoredConsoleTarget
            {
                Layout = "${message} ${exception:format=tostring}"
            };

        var debuggerTarget = new DebuggerTarget()
        {
            Layout = "${message} ${exception:format=tostring}"
        };

        var consoleRule = new LoggingRule("*", LogLevel.Debug, consoleTarget);
        var debuggerRule = new LoggingRule("*", LogLevel.Debug, debuggerTarget);

        var config = new LoggingConfiguration();

        config.LoggingRules.Add(consoleRule);
        config.LoggingRules.Add(debuggerRule);

        config.AddTarget("debugger", debuggerTarget);
        config.AddTarget("console", consoleTarget);

        LogManager.Configuration = config;
    }
開發者ID:rwecho,項目名稱:Experiments,代碼行數:25,代碼來源:LoggingFactory.cs

示例3: ConfigureViaCode

        public static void ConfigureViaCode(LogLevel consoleLogLevel, LogLevel fileLogLevel)
        {
            // Step 1. Create configuration object
            var config = new LoggingConfiguration();

            // Step 2. Create targets and add them to the configuration
            var consoleTarget = new ConsoleTarget();
            config.AddTarget("console", consoleTarget);

            var fileTarget = new FileTarget();
            config.AddTarget("file", fileTarget);

            // Step 3. Set target properties
            consoleTarget.Layout = @"${message} ${onexception:EXCEPTION\:${exception:format=tostring}}";

            fileTarget.Layout = @"${date:format=yyyy-MM-dd HH\:mm\:ss.fff} [${level:uppercase=true}] ${message}  ${onexception:EXCEPTION\:${exception:format=tostring}}";
            fileTarget.FileName = "C:\\temp\\logs\\SpiderOpenQuant.${date:format=yyyy-MM-dd hh}.log";
            fileTarget.ConcurrentWrites = false;
            fileTarget.KeepFileOpen = true;
            fileTarget.OpenFileCacheTimeout = 60;

            // Step 4. Define rules
            var rule1 = new LoggingRule("*", consoleLogLevel, consoleTarget);
            config.LoggingRules.Add(rule1);

            var rule2 = new LoggingRule("*", fileLogLevel, fileTarget);
            config.LoggingRules.Add(rule2);

            // Step 5. Activate the configuration
            LogManager.Configuration = config;
        }
開發者ID:aggarwalmanuj,項目名稱:open-quant,代碼行數:31,代碼來源:LogConfigurator.cs

示例4: CreateLogger

        private static Logger CreateLogger()
        {
            var config = new LoggingConfiguration();

            var fileTarget = new FileTarget();
            config.AddTarget("file", fileTarget);

            fileTarget.FileName = "${basedir}\\AsteriskLog.txt";
            fileTarget.Layout = "${date:format=yyyy-MM-dd HH\\:mm\\:ss}: ${message}";
            fileTarget.ArchiveFileName = "${basedir}\\archives\\log.{#####}.txt";
            fileTarget.ArchiveAboveSize = 10240000;
            fileTarget.ArchiveNumbering = ArchiveNumberingMode.Sequence;

            var rule = new LoggingRule("*", LogLevel.Trace, fileTarget);
            config.LoggingRules.Add(rule);

            var errorTarget = new FileTarget();
            config.AddTarget("errorfile", errorTarget);

            errorTarget.FileName = "${basedir}\\Errors.txt";
            errorTarget.Layout = "${date:format=yyyy-MM-dd HH\\:mm\\:ss}: ${message}";
            errorTarget.ArchiveFileName = "${basedir}\\archives\\log.{#####}.txt";
            errorTarget.ArchiveAboveSize = 10240000;
            errorTarget.ArchiveNumbering = ArchiveNumberingMode.Sequence;

            var errorsRule = new LoggingRule("*", LogLevel.Error, errorTarget);
            config.LoggingRules.Add(errorsRule);

            LogManager.Configuration = config;

            return LogManager.GetCurrentClassLogger();
        }
開發者ID:Madster9000,項目名稱:CallCenter,代碼行數:32,代碼來源:NLogContaner.cs

示例5: SetupLogging

        private void SetupLogging()
        {
            // Step 1. Create configuration object
            LoggingConfiguration configuration = new LoggingConfiguration();

            // Step 2. Create targets and add them to the configuration
            FileTarget fileTarget = new FileTarget();
            configuration.AddTarget("file", fileTarget);

            NLogViewerTarget log_viewer_target = new NLogViewerTarget();
            log_viewer_target.Name = "viewer";
            log_viewer_target.Address = "udp://127.0.0.1:9999";
            configuration.AddTarget("viewer", log_viewer_target);

            // Step 3. Set target properties
            fileTarget.FileName = "${basedir}/file.txt";
            fileTarget.Layout = "${date} ${level} ${message}";

            // Step 4. Define rules
            LoggingRule rule1 = new LoggingRule("*", LogLevel.Debug, fileTarget);
            configuration.LoggingRules.Add(rule1);

            LoggingRule rule2 = new LoggingRule("*", LogLevel.Trace, log_viewer_target);
            configuration.LoggingRules.Add(rule2);

            // Step 5. Activate the configuration
            LogManager.Configuration = configuration;

            // Example usage
            log.Debug("Application started");
        }
開發者ID:lycilph,項目名稱:Projects,代碼行數:31,代碼來源:App.xaml.cs

示例6: configureLogger

        private void configureLogger()
        {
            var config = new LoggingConfiguration();

            var consoleTarget = new ColoredConsoleTarget();
            config.AddTarget("console", consoleTarget);

            var fileTarget = new FileTarget();
            config.AddTarget("file", fileTarget);
            consoleTarget.Layout = @"${date:format=HH\:MM\:ss} ${logger} ${message}";
            fileTarget.FileName = "${basedir}/logs/${shortdate}.log";
            fileTarget.EnableFileDelete = true;
            fileTarget.DeleteOldFileOnStartup = true;
            fileTarget.Layout = "${message}";

            var rule1 = new LoggingRule("*", LogLevel.Trace, consoleTarget);
            config.LoggingRules.Add(rule1);

            var rule2 = new LoggingRule("*", LogLevel.Trace, fileTarget);
            config.LoggingRules.Add(rule2);

            LogManager.Configuration = config;

            log = LogManager.GetLogger("SeleniumTests");
        }
開發者ID:HarryMcCarney,項目名稱:SeleniumHarness,代碼行數:25,代碼來源:Globals.cs

示例7: InitNLog

    public void InitNLog()
    {
        // Step 1. Create configuration object
        NLog.Config.LoggingConfiguration gConfig = new NLog.Config.LoggingConfiguration();

        // Step 2. Create targets and add them to the configuration
        NLog.Targets.ColoredConsoleTarget consoleTarget = new NLog.Targets.ColoredConsoleTarget();
        gConfig.AddTarget("console", consoleTarget);

        NLog.Targets.FileTarget fileTarget = new NLog.Targets.FileTarget();
        gConfig.AddTarget("file", fileTarget);

        // Step 3. Set target properties
        consoleTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";
        fileTarget.FileName = System.IO.Directory.GetCurrentDirectory() + "/${shortdate}/${logger}.log";
        fileTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";

        UnityEngine.Debug.Log(fileTarget.FileName);

        // Step 4. Define rules
        NLog.Config.LoggingRule rule1 = new NLog.Config.LoggingRule("*", NLog.LogLevel.Debug, consoleTarget);
        gConfig.LoggingRules.Add(rule1);

        NLog.Config.LoggingRule rule2 = new NLog.Config.LoggingRule("*", NLog.LogLevel.Debug, fileTarget);
        gConfig.LoggingRules.Add(rule2);

        // Step 5. Activate the configuration
        NLog.LogManager.Configuration = gConfig;
    }
開發者ID:unigame,項目名稱:uniGame,代碼行數:29,代碼來源:NLogConfigManager.cs

示例8: SetupLogging

        private static void SetupLogging() {
            // Step 1. Create configuration object 
            LoggingConfiguration config = new LoggingConfiguration();

            // Step 2. Create targets and add them to the configuration 
            ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget();
            config.AddTarget("console", consoleTarget);

            FileTarget fileTarget = new FileTarget();
            config.AddTarget("file", fileTarget);
            fileTarget.FileName = "${basedir}/file.txt";

            // Step 3. Set target properties 
            consoleTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";
            fileTarget.Layout = "${date:format=HH\\:MM\\:ss} ${message}";

            // Step 4. Define rules
            LoggingRule rule = new LoggingRule("*", LogLevel.Debug, consoleTarget);
            config.LoggingRules.Add(rule);

            rule = new LoggingRule("*", LogLevel.Debug, fileTarget);
            config.LoggingRules.Add(rule);

            // Step 5. Activate the configuration
            LogManager.Configuration = config;
        }
開發者ID:onpoint,項目名稱:ProjectExtensions.Azure.ServiceBus,代碼行數:26,代碼來源:Program.cs

示例9: LocalLogger

        static LocalLogger()
        {
            // Creating new Logger from current class
            _logger = LogManager.GetLogger(nameof(LocalLogger));

            var loggerFilePath = System.Configuration.ConfigurationManager.AppSettings["loggerFilePath"];
            var loggerFileName = $"{LogFileName}.{DateTime.Now:yyy-MM-dd}.log"; //$"{Environment.CurrentDirectory}/{LogFileName}.{DateTime.Now:yyy-MM-dd}.log";

            // File Target Configuration
            var logFileTarget = new FileTarget
            {
                Name = LogFileName,
                FileName = $"{loggerFilePath}/{loggerFileName}",
                Layout = string.Format("{0:yyy-MM-dd hh:mm} :: [{1}] :: {2} -> {3}", DateTime.Now, "${level}", "${message}", "${exception}")
            };
            logFileTarget.ArchiveEvery = FileArchivePeriod.Hour;
            logFileTarget.ArchiveNumbering = ArchiveNumberingMode.Rolling;
            logFileTarget.ArchiveFileName = new SimpleLayout($"{LogFileName}_#####.log");

            // Logging Rule Configuration
            var logRule = new LoggingRule("*", LogLevel.Info, logFileTarget);

            // New LoggingConfiguration Object
            var logConfig = new LoggingConfiguration();

            // Configuring Target and Rules to LoggingConfiguration
            logConfig.AddTarget(LogFileName, logFileTarget);
            logConfig.LoggingRules.Add(logRule);

            // Setting new LoggingConfiguration
            LogManager.Configuration = logConfig;
        }
開發者ID:higtrollers,項目名稱:BooAppRepository,代碼行數:32,代碼來源:LocalLogger.cs

示例10: ConfigLogging

        private void ConfigLogging()
        {
            var config = new LoggingConfiguration();

            var target = new DebuggerTarget
            {
                Layout = @"${date:format=HH\\:MM\\:ss} ${logger} ${message}"
            };

            var sqlTarget = new FileTarget
            {
                Layout = @"${date:format=HH\\:MM\\:ss} ${logger} ${message}",
                FileName = "sql.log"
            };

            var rule = new LoggingRule( "*", LogLevel.Trace, target );
            var sqlRule = new LoggingRule( "NHibernate", LogLevel.Trace, sqlTarget );

            config.AddTarget( "sql", sqlTarget );
            config.AddTarget( "debugger", target );
            config.LoggingRules.Add( sqlRule );
            config.LoggingRules.Add( rule );

            LogManager.Configuration = config;
        }
開發者ID:TheSylence,項目名稱:DeVi,代碼行數:25,代碼來源:App.xaml.cs

示例11: UsingLoggingAspectWithNLogShouldUseNlogger

        public void UsingLoggingAspectWithNLogShouldUseNlogger()
        {
            // arrange - setup nlog
            LoggingConfiguration config = new LoggingConfiguration();

            MemoryTarget memoryTarget = new MemoryTarget { Layout = @"${message}" };
            config.AddTarget("memory", memoryTarget);

            LoggingRule rule = new LoggingRule("*", LogLevel.Debug, memoryTarget);
            config.LoggingRules.Add(rule);

            LogManager.Configuration = config;

            Mock<IConfigurationProvider> mock = new Mock<IConfigurationProvider>();
            mock.Setup(provider => provider.ShouldLog(It.IsAny<LogAttribute>())).Returns(true);
            LogAttribute.ConfigurationProvider = mock.Object;

            // arrange - setup logger
            LogAttribute.Logger = new NLogLogger("memory");

            // act
            Person person = new Person { Name = "test", Balance = 0.0d };
            person.Should().NotBeNull();

            // assert
            memoryTarget.Logs.Count.Should().Be(9, "because we called the logging 9 times");
        }
開發者ID:vnvizitiu,項目名稱:AOP,代碼行數:27,代碼來源:NlogsLoggingAspectTests.cs

示例12: ConfigureForTargetLogging

 /// <summary>
 /// Configures NLog for to log to the specified target so that all messages 
 /// above and including the specified level are output.
 /// </summary>
 /// <param name="target">The target to log all messages to.</param>
 /// <param name="minLevel">The minimal logging level.</param>
 public static void ConfigureForTargetLogging(Target target, LogLevel minLevel)
 {
     LoggingConfiguration config = new LoggingConfiguration();
     LoggingRule rule = new LoggingRule("*", minLevel, target);
     config.LoggingRules.Add(rule);
     LogManager.Configuration = config;
 }
開發者ID:ExM,項目名稱:NLog,代碼行數:13,代碼來源:SimpleConfigurator.cs

示例13: Initialize

        public void Initialize()
        {
            // Step 1. Create configuration object 
            var config = new LoggingConfiguration();
            
            // Step 2. Create targets and add them to the configuration 
            var fileTarget = new FileTarget();
            config.AddTarget("file", fileTarget);

            var logentriesTarget = new Le.LeTarget();
            config.AddTarget("logentries", logentriesTarget);
            
            // Step 3. Set target properties 
            fileTarget.FileName = "${specialfolder:folder=LocalApplicationData}/" + GlobalConstants.Paths.LogFile;
            fileTarget.Layout = layout;
            logentriesTarget.Layout = layout;
            
            // Step 4. Define rules
            var rule1 = new LoggingRule("*", LogLevel.Info, fileTarget);
            config.LoggingRules.Add(rule1);

            var rule2 = new LoggingRule("*", LogLevel.Info, logentriesTarget);
            config.LoggingRules.Add(rule2);
            
            // Step 5. Activate the configuration
            LogManager.Configuration = config;
        }
開發者ID:jcteague,項目名稱:dtt,代碼行數:27,代碼來源:NLogConfiguration.cs

示例14: Configure

        public static void Configure()
        {
            // Step 1. Create configuration object
            var config = new LoggingConfiguration();

            // Step 2. Create targets and add them to the configuration
            var consoleTarget = new ColoredConsoleTarget();
            config.AddTarget("console", consoleTarget);

            var fileTarget = new FileTarget();
            config.AddTarget("file", fileTarget);

            // Step 3. Set target properties
            consoleTarget.Layout = @"${date:format=HH\:mm\:ss} ${logger} ${message}";
            fileTarget.FileName = "${basedir}/SimplePerformanceMeter.txt";
            fileTarget.Layout = "${message}";

            // Step 4. Define rules
            var rule1 = new LoggingRule("*", LogLevel.Debug, consoleTarget);
            config.LoggingRules.Add(rule1);

            var rule2 = new LoggingRule("*", LogLevel.Debug, fileTarget);
            config.LoggingRules.Add(rule2);

            // Step 5. Activate the configuration
            LogManager.Configuration = config;
        }
開發者ID:jansaris,項目名稱:SimplePerformanceMeter,代碼行數:27,代碼來源:NLog.cs

示例15: LoadLoggerToLoggingConfig

 public static void LoadLoggerToLoggingConfig(LoggingConfiguration logConfig, IConfiguration Configuration,string sectionString)
 {
     var fileLoggerSection = Configuration.GetSection(sectionString).GetChildren();
     foreach (var logging in fileLoggerSection)
     {
         var target = new FileTarget()
         {
             FileName = logging["fileName"],
             Name = logging["name"],
             Layout = logging["layoutFormat"]
         };
         var minLevel = logging["minLevel"] != null ? LogLevel.FromString(logging["minLevel"]) : null;
         LoggingRule rule = null;
         if (minLevel != null)
         {
             rule = new LoggingRule(logging["namePattern"], minLevel, target);
         }
         else
         {
             rule = new LoggingRule(logging["namePattern"], target);
         }
         var useLevels = logging["logLevel"];
         if(string.IsNullOrWhiteSpace(useLevels) == false)
         {
             var levels = useLevels.Split(',');
             foreach (var level in levels)
             {
                 rule.EnableLoggingForLevel(LogLevel.FromString(level));
             }
         }
         logConfig.AddTarget(target);
         logConfig.LoggingRules.Add(rule);
     }
 }
開發者ID:Sharelink,項目名稱:BahamutZero,代碼行數:34,代碼來源:LoggerLoaderHelper.cs


注:本文中的NLog.Config.LoggingRule類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。