本文整理汇总了C#中NLog.Targets.ColoredConsoleTarget类的典型用法代码示例。如果您正苦于以下问题:C# ColoredConsoleTarget类的具体用法?C# ColoredConsoleTarget怎么用?C# ColoredConsoleTarget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ColoredConsoleTarget类属于NLog.Targets命名空间,在下文中一共展示了ColoredConsoleTarget类的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;
}
示例2: 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;
}
示例3: 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;
}
示例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: ExamplePrograms
public ExamplePrograms()
{
var loggerNamePattern = "BitSharp.Examples.*";
var logLevel = LogLevel.Info;
// log layout format
var layout = "${message} ${exception:separator=\r\n:format=message,type,method,stackTrace:maxInnerExceptionLevel=10:innerExceptionSeparator=\r\n:innerFormat=message,type,method,stackTrace}";
// initialize logging configuration
var config = new LoggingConfiguration();
// create console target
var consoleTarget = new ColoredConsoleTarget();
consoleTarget.Layout = layout;
config.AddTarget("console", consoleTarget);
config.LoggingRules.Add(new LoggingRule(loggerNamePattern, logLevel, consoleTarget));
// create debugger target, if attached
if (Debugger.IsAttached)
{
var debuggerTarget = new DebuggerTarget();
debuggerTarget.Layout = layout;
config.AddTarget("debugger", debuggerTarget);
config.LoggingRules.Add(new LoggingRule(loggerNamePattern, logLevel, debuggerTarget));
}
LogManager.Configuration = config;
logger = LogManager.GetCurrentClassLogger();
}
示例6: Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
#if DNX451
var config = new LoggingConfiguration();
// Step 2. Create targets and add them to the configuration
var consoleTarget = new ColoredConsoleTarget();
config.AddTarget("console", consoleTarget);
consoleTarget.Layout = @"${date:format=HH\\:MM\\:ss} ${ndc} ${logger} ${message} ";
var rule1 = new LoggingRule("*", NLog.LogLevel.Debug, consoleTarget);
config.LoggingRules.Add(rule1);
loggerFactory.AddNLog(new global::NLog.LogFactory(config));
#endif
app.UseErrorPage()
.UseStaticFiles()
.UseIdentity()
.UseFacebookAuthentication()
.UseGoogleAuthentication()
.UseTwitterAuthentication()
.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
//Populates the Admin user and role
SampleData.InitializeIdentityDatabaseAsync(app.ApplicationServices).Wait();
}
示例7: 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;
}
示例8: Load
public override void Load()
{
// log layout format
var layout = "${date:format=hh\\:mm\\:ss tt} ${pad:padding=6:inner=${level:uppercase=true}} ${message} ${exception:separator=\r\n:format=message,type,method,stackTrace:maxInnerExceptionLevel=10:innerExceptionSeparator=\r\n:innerFormat=message,type,method,stackTrace}";
// initialize logging configuration
var config = new LoggingConfiguration();
// create console target
if (!Debugger.IsAttached)
{
var consoleTarget = new ColoredConsoleTarget();
consoleTarget.Layout = layout;
config.AddTarget("console", consoleTarget);
config.LoggingRules.Add(new LoggingRule("*", this.logLevel, consoleTarget));
}
else
{
var consoleTarget = new DebuggerTarget();
consoleTarget.Layout = layout;
config.AddTarget("console", consoleTarget);
config.LoggingRules.Add(new LoggingRule("*", this.logLevel, consoleTarget));
}
// activate configuration and bind
LogManager.Configuration = config;
}
示例9: 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);
}
示例10: ConfigureConsoleOutput
//-----------------------------------------------------------------------------------------------------------------------------------------------------
public void ConfigureConsoleOutput()
{
var consoleTarget = new ColoredConsoleTarget();
consoleTarget.Layout = @"${date:universalTime=true:format=HH\:mm\:ss.fff} ${message} ${exception:format=Message}";
consoleTarget.UseDefaultRowHighlightingRules = false;
consoleTarget.RowHighlightingRules.Clear();
consoleTarget.RowHighlightingRules.Add(new ConsoleRowHighlightingRule(
"level == LogLevel.Trace and starts-with('${message}','[THREAD:')", ConsoleOutputColor.Cyan, ConsoleOutputColor.Black));
consoleTarget.RowHighlightingRules.Add(new ConsoleRowHighlightingRule(
"level == LogLevel.Trace", ConsoleOutputColor.DarkCyan, ConsoleOutputColor.Black));
consoleTarget.RowHighlightingRules.Add(new ConsoleRowHighlightingRule(
"level == LogLevel.Debug", ConsoleOutputColor.DarkGray, ConsoleOutputColor.Black));
consoleTarget.RowHighlightingRules.Add(new ConsoleRowHighlightingRule(
"level == LogLevel.Info", ConsoleOutputColor.White, ConsoleOutputColor.Black));
consoleTarget.RowHighlightingRules.Add(new ConsoleRowHighlightingRule(
"level == LogLevel.Warn", ConsoleOutputColor.Yellow, ConsoleOutputColor.Black));
consoleTarget.RowHighlightingRules.Add(new ConsoleRowHighlightingRule(
"level >= LogLevel.Error", ConsoleOutputColor.Red, ConsoleOutputColor.Black));
LogManager.Configuration.AddTarget(PlainTextConsoleTargetName, consoleTarget);
var consoleRule = new LoggingRule(PlainTextLoggerName, LogLevel.Trace, consoleTarget);
LogManager.Configuration.LoggingRules.Add(consoleRule);
LogManager.ReconfigExistingLoggers();
}
示例11: 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("");
}
示例12: 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;
}
示例13: 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");
}
示例14: 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;
}
示例15: 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;
}