NLog.Config.LoggingConfiguration.AddTarget C# (CSharp) Method

AddTarget() public method

Registers the specified target object under a given name.
public AddTarget ( string name, Target target ) : void
name string /// Name of the target. ///
target NLog.Targets.Target /// The target object. ///
return void
        public void AddTarget(string name, Target target)
        {
            if (name == null)
            {
                throw new ArgumentException("Target name cannot be null", "name");
            }

            InternalLogger.Debug("Registering target {0}: {1}", name, target.GetType().FullName);
            this.targets[name] = target;
        }

Usage Example

		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");
		}
All Usage Examples Of NLog.Config.LoggingConfiguration::AddTarget