本文整理汇总了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");
}
示例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;
}
示例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);
}
示例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;
}
示例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("");
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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");
}
示例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");
}
示例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;
}
示例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;
}
示例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;
}