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


C# LoggingConfiguration.AddTarget方法代碼示例

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


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

示例1: NLogLogProviderLoggingEnabledTests

		public NLogLogProviderLoggingEnabledTests()
		{
			NLogLogManager.ProviderIsAvailableOverride = true;
			var config = new LoggingConfiguration();

			simpleLayoutTarget = new MemoryTarget
			{
				Layout = "${level:uppercase=true}|${message}|${exception}"
			};
			ndcLayoutTarget = new MemoryTarget
			{
				Layout = "${level:uppercase=true}|${ndc:bottomFrames=10:topFrames=10:separator=;}|${message}|${exception}"
			};
			mdcLayoutTarget = new MemoryTarget
			{
				Layout = "${level:uppercase=true}|${mdc:item=Key}|${message}|${exception}"
			};
			config.AddTarget("simpleLayoutMemory", simpleLayoutTarget);
			config.AddTarget("mdcLayoutTarget", mdcLayoutTarget);
			config.AddTarget("ndcLayoutMemory", ndcLayoutTarget);
			config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, simpleLayoutTarget));
			config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, mdcLayoutTarget));
			config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, ndcLayoutTarget));
			LogManager.Configuration = config;
			nLogLogManager = new NLogLogManager();
			sut = nLogLogManager.GetLogger("Test");
		}
開發者ID:WimVergouwe,項目名稱:ravendb,代碼行數:27,代碼來源:NLogLogProviderLoggingEnabledTests.cs

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

示例3: SetupLogging

    // ------------------------------------------
    //  Logs Management
    // ------------------------------------------

    protected void SetupLogging() {
      var path = ConfigManager.GetInstance().Find("debug.log-file", null);
      if (null == path) { return; }
      
      LoggingConfiguration config = new LoggingConfiguration();

      ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget();
      consoleTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";
      config.AddTarget("console", consoleTarget);

      FileTarget fileTarget = new FileTarget();
      fileTarget.FileName = path;
      fileTarget.Layout = "${message}";
      fileTarget.CreateDirs = true;
      config.AddTarget("file", fileTarget);

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

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

      LoggingRule rule3 = new LoggingRule("*", LogLevel.Warn, consoleTarget);
      config.LoggingRules.Add(rule3);

      LoggingRule rule4 = new LoggingRule("*", LogLevel.Warn, fileTarget);
      config.LoggingRules.Add(rule4);

      // Ready
      LogManager.ReconfigExistingLoggers();
      LogManager.Configuration = config;
      Host.Log(this, "STARTING LOGGING:" + fileTarget.FileName);
    }
開發者ID:JpEncausse,項目名稱:SARAH-Client-Windows,代碼行數:37,代碼來源:AddOn.cs

示例4: Configure

        private static void Configure(INewRelicConfig config)
        {
            config = config ?? NewRelicConfig.Instance;
            LoggingConfiguration loggingConfiguration = new LoggingConfiguration();
            ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget { Name = "Console" };
            loggingConfiguration.AddTarget("Console", consoleTarget);
            loggingConfiguration.LoggingRules.Add(new LoggingRule("*", ToNLogLevel(config.LogLevel), consoleTarget));

            // Store the LogLevel so it can be fetched by consumers
            LogLevel = config.LogLevel;

            if (config.LogFilePath.IsValidString() && config.LogFileName.IsValidString())
            {
                long archiveAboveSize = config.LogLimitInKiloBytes == 0 ? long.MaxValue : config.LogLimitInKiloBytes * 1024;
                FileTarget fileTarget = new FileTarget
                {
                    KeepFileOpen = true,
                    ConcurrentWrites = false,
                    FileName = Path.Combine(config.LogFilePath, config.LogFileName),
                    MaxArchiveFiles = 1,
                    ArchiveAboveSize = archiveAboveSize,
                    Name = "File",
                };

                loggingConfiguration.AddTarget("File", fileTarget);
                loggingConfiguration.LoggingRules.Add(new LoggingRule("*", ToNLogLevel(config.LogLevel), fileTarget));
            }

            NLogManager.Configuration = loggingConfiguration;
        }
開發者ID:edwinf,項目名稱:newrelic_dotnet_sdk,代碼行數:30,代碼來源:Logger.cs

示例5: BuildLogger

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

        var fileName = Path.Combine(Path.GetTempPath(), "NancyOnKayak", "WebsiteLog_${shortdate}.log");
        Console.WriteLine("Logging to:" + fileName);

        var fileTarget = new FileTarget
                             {
                                 FileName = fileName,
                                 Layout = "${longdate} ${message} ${exception:format=tostring}",
                                 AutoFlush = true,
                             };

        var config = new LoggingConfiguration
                         {
                             LoggingRules =
                                 {
                                     new LoggingRule("*", LogLevel.Debug, consoleTarget),
                                     new LoggingRule("*", LogLevel.Debug, fileTarget),
                                 }
                         };

        config.AddTarget("file", fileTarget);
        config.AddTarget("console", consoleTarget);

        LogManager.Configuration = config;
        return LogManager.GetLogger("");
    }
開發者ID:rwecho,項目名稱:Experiments,代碼行數:32,代碼來源:LoggingFactory.cs

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

示例7: Configure

        public static void Configure()
        {
            var config = new LoggingConfiguration();
            var fileTarget = new FileTarget();

            fileTarget.FileName = Path.Combine(Util.get_log_folder(), "btnet_log.txt");
            fileTarget.ArchiveNumbering = ArchiveNumberingMode.Date;
            fileTarget.ArchiveEvery = FileArchivePeriod.Day;
            config.AddTarget("File", fileTarget);

            var mailTarget = new MailTarget
            {
                UseSystemNetMailSettings = true,
                To = Util.get_setting("ErrorEmailTo", ""),
                From = Util.get_setting("ErrorEmailFrom", ""),
                Subject = "BTNET Error Notification",
                Layout = "${machinename}${newline} ${date} ${newline} ${newline} ${message} ${newline}  ${exception} ${newline}"
            };
            config.AddTarget("Mail", mailTarget);

            //Turn logging on/off based on the LogEnabled setting
            var logLevel = Util.get_setting("LogEnabled", "1") == "1" ? LogLevel.Trace: LogLevel.Off;
            config.LoggingRules.Add(new LoggingRule("*", logLevel, fileTarget));

            var emailLogLevel = Util.get_setting("ErrorEmailEnabled", "1") == "1" ? LogLevel.Fatal : LogLevel.Off;
            config.LoggingRules.Add(new LoggingRule("*", emailLogLevel, mailTarget));

            LogManager.Configuration = config;
        }
開發者ID:jhadwen,項目名稱:BugTracker.NET,代碼行數:29,代碼來源:LoggingConfig.cs

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

示例9: InitLogging

        private static void InitLogging()
        {
            var s_Config = new LoggingConfiguration();

            var s_ConsoleTarget = new ColoredConsoleTarget();
            s_Config.AddTarget("console", s_ConsoleTarget);

            s_ConsoleTarget.Layout = @"[${date:format=HH\:mm\:ss.fff}] ${logger} >> ${message}";

            var s_ConsoleRule = new LoggingRule("*", LogLevel.Trace, s_ConsoleTarget);
            s_Config.LoggingRules.Add(s_ConsoleRule);

            var s_FileTarget = new FileTarget();
            s_Config.AddTarget("file", s_FileTarget);

            s_FileTarget.FileName = "${basedir}/GrooveCaster.log";
            s_FileTarget.Layout = @"[${date:format=HH\:mm\:ss.fff}] ${logger} >> ${message}";
            s_FileTarget.ArchiveFileName = "${basedir}/GrooveCaster.{#}.log";
            s_FileTarget.ArchiveEvery = FileArchivePeriod.Day;
            s_FileTarget.ArchiveNumbering = ArchiveNumberingMode.Date;
            s_FileTarget.ArchiveDateFormat = "yyyMMdd";

            var s_FileRule = new LoggingRule("*", LogLevel.Trace, s_FileTarget);
            s_Config.LoggingRules.Add(s_FileRule);

            LogManager.Configuration = s_Config;
        }
開發者ID:WildGenie,項目名稱:GrooveCaster,代碼行數:27,代碼來源:Program.cs

示例10: ConfigureLogger

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

            var consoleTarget = new ColoredConsoleTarget();
            config.AddTarget("console", consoleTarget);
            var logsDirPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                                           "Yakuza", "Jira Assistant", "Logs");

            if (Directory.Exists(logsDirPath) == false)
                Directory.CreateDirectory(logsDirPath);

            var fileTarget = new FileTarget
            {
                Name = "main",
                FileName = Path.Combine(logsDirPath, "Jira Assistant.log"),
                Layout = "${longdate} ${uppercase:${level}} ${message} ${exception:format=tostring}",
                ArchiveFileName = Path.Combine(logsDirPath, "Jira Assistant.{#}.log"),
                ArchiveEvery = FileArchivePeriod.Day,
                ArchiveNumbering = ArchiveNumberingMode.Rolling,
                MaxArchiveFiles = 3,
                ConcurrentWrites = true
            };
            config.AddTarget("file", fileTarget);

            config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));
            config.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, fileTarget));

            LogManager.Configuration = config;
        }
開發者ID:sceeter89,項目名稱:jira-client,代碼行數:30,代碼來源:App.xaml.cs

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

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

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

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

示例15: ConfigureNLog

    public static void ConfigureNLog()
    {
        var config = new LoggingConfiguration();

        var consoleTarget = new ColoredConsoleTarget
        {
            Layout = "${level:uppercase=true}|${logger}|${message}${onexception:${newline}${exception:format=tostring}}"
        };
        config.AddTarget("console", consoleTarget);
        config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget));

        var fileTarget = new FileTarget
        {
            FileName = "${basedir}/nsb_log_${date:format=yyyy-MM-dd}.txt",
            ArchiveDateFormat = "yyyy-MM-dd",
            Layout = "${longdate}|${level:uppercase=true}|${logger}|${message}${onexception:${newline}${exception:format=tostring}}",
            ArchiveAboveSize = 10 * 1024 *1024,
            ArchiveEvery = FileArchivePeriod.Day,
            ArchiveNumbering = ArchiveNumberingMode.Rolling,
            MaxArchiveFiles = 10,
            KeepFileOpen = false
        };
        config.AddTarget("file", fileTarget);
        config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget));

        LogManager.Configuration = config;

    }
開發者ID:jmwhicke,項目名稱:NServiceBus.NLog,代碼行數:28,代碼來源:LoggingConfig.cs


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