本文整理汇总了C#中NLog.LogLevel类的典型用法代码示例。如果您正苦于以下问题:C# LogLevel类的具体用法?C# LogLevel怎么用?C# LogLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LogLevel类属于NLog命名空间,在下文中一共展示了LogLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: Compile
public void Compile(DroneEnv env, LogLevel logLevel)
{
if (this.IsRecompileNeeded(env.Config))
{
var result = this.CompileCore(env);
try
{
if (result.IsSuccess)
{
this.CreateCache(env.Config);
this.log.Log(logLevel, "compiled ({0})", HumanTime.Format(result.TimeElapsed));
}
else
{
throw DroneCompilerException.Get(result);
}
}
finally
{
this.LogResult(result);
}
}
else
{
this.log.Log(logLevel, "compiliation skipped, all files up to date");
}
}
示例3: DicomParserLogger
public DicomParserLogger(Logger log, LogLevel level)
{
_log = log;
_level = level;
_depth = 0;
_pad = String.Empty;
}
示例4: Configure
public static void Configure(LogLevel logLevel = null)
{
logLevel = logLevel ?? LogLevel.Info;
// 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 = LogManager.Configuration ?? new LoggingConfiguration();
// create console target
if (!Debugger.IsAttached)
{
var consoleTarget = new ColoredConsoleTarget();
consoleTarget.Layout = layout;
config.AddTarget("console", consoleTarget);
config.LoggingRules.Add(new LoggingRule("*", logLevel, consoleTarget));
}
else
{
var consoleTarget = new DebuggerTarget();
consoleTarget.Layout = layout;
config.AddTarget("console", consoleTarget);
config.LoggingRules.Add(new LoggingRule("*", logLevel, consoleTarget));
}
// activate configuration and bind
LogManager.Configuration = config;
}
示例5: Write
public void Write(CommonLogger logType, LogLevel level, string message)
{
Logger logger = LoggerRepository.BuildLogger(logType);
StringBuilder info = new StringBuilder();
if (HttpContext.Current != null)
{
var urlReferrer = HttpContext.Current.Request.UrlReferrer;
if (urlReferrer != null)
{
info.AppendLine("前一个请求地址:" + urlReferrer.ToString());
}
var behavior = HttpContext.Current.Request.Cookies["user"];
if (behavior != null)
{
info.AppendLine("据用户跟踪,用户为:" + behavior);
}
info.AppendLine("MethodType:" + HttpContext.Current.Request.HttpMethod);
info.AppendLine("ClientIP:" + HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString());
info.AppendLine("Browser:" + HttpContext.Current.Request.Browser.Type);
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
info.AppendLine("LoginUser:" + HttpContext.Current.User.Identity.Name);
}
info.AppendLine("请求地址:" + HttpContext.Current.Request.RawUrl);
}
DoWrite(logger, level, info.ToString() + message);
}
示例6: testLogLevel
void testLogLevel(Action<string> logMethod, LogLevel logLvl, bool shouldLog)
{
var didLog = false;
LogLevel eventLogLevel = LogLevel.Off;
string eventMessage = null;
Logger eventLogger = null;
_logger.OnLog += (logger, logLevel, msg) => {
didLog = true;
eventLogger = logger;
eventLogLevel = logLevel;
eventMessage = msg;
};
logMethod(Message);
didLog.should_be(shouldLog);
if (shouldLog) {
eventLogger.should_be_same(_logger);
eventMessage.should_be(Message);
eventLogLevel.should_be(logLvl);
} else {
eventMessage.should_be_null();
eventLogLevel.should_be(LogLevel.Off);
eventLogger.should_be_null();
}
}
示例7: Log
public void Log(string s, LogLevel level)
{
var box = level == LogLevel.Debug || level == LogLevel.Info || level == LogLevel.Trace ? infoBox : logBox;
while (box.Items.Count > 8)
box.Items.RemoveAt(0);
box.Items.Add(s);
}
示例8: Log
public void Log(LogLevel level, object value)
{
if (this.IsEnabled(level))
{
this.WriteToTargets(level, "{0}", new object[] { value });
}
}
示例9: SetChainsawLevel
private static void SetChainsawLevel(LogLevel minimumLevel)
{
SetTargetLevel(
ChainsawTargetName,
minimumLevel,
targetName => new ChainsawTarget { Name = targetName, Address = "udp://127.0.0.1:7071" });
}
示例10: LogMessageModel
public LogMessageModel(string message, LogLevel level, DateTime date)
{
this.Date = date;
this.message = message;
this.level = level;
IsVisible = true;
}
示例11: SendPayload
private void SendPayload(LogLevel level, string message, Exception exception)
{
if (exception == null)
{
return;
}
string exceptionType;
var stackBuilder = new StringBuilder();
do
{
exceptionType = exception.GetType().Name;
stackBuilder.AppendLine(exception.Message);
stackBuilder.AppendLine(exception.StackTrace);
exception = exception.InnerException;
} while (exception != null);
manager.SendLoggingPayload(new LoggingPayload
{
StackTrace = stackBuilder.ToString(),
Message = message,
LogLevel = level.Name,
ExceptionType = exceptionType
});
}
示例12: LogNode
public LogNode(XmlNode xmlNode, ScriptableScraper context)
: base(xmlNode, context)
{
try { logLevel = LogLevel.FromString(xmlNode.Attributes["LogLevel"].Value); }
catch (Exception e) {
if (e.GetType() == typeof(ThreadAbortException))
throw e;
try { logLevel = LogLevel.FromString(xmlNode.Attributes["log_level"].Value); }
catch (Exception e2) {
if (e2.GetType() == typeof(ThreadAbortException))
throw e2;
logLevel = LogLevel.Debug;
}
}
try { message = xmlNode.Attributes["Message"].Value; }
catch (Exception e) {
if (e.GetType() == typeof(ThreadAbortException))
throw e;
try { message = xmlNode.Attributes["message"].Value; }
catch (Exception e2) {
if (e2.GetType() == typeof(ThreadAbortException))
throw e2;
logger.Error("Missing MESSAGE attribute on: " + xmlNode.OuterXml);
loadSuccess = false;
return;
}
}
loadSuccess = true;
}
示例13: SetNLogTarget
public static void SetNLogTarget(Target target, LogLevel minLevel = null)
{
if (target != null)
{
SimpleConfigurator.ConfigureForTargetLogging(target, minLevel ?? LogLevel.Info);
}
}
示例14: LogProgressMessage
private static void LogProgressMessage(Logger logger, LogLevel level, string message)
{
var logEvent = new LogEventInfo(level, logger.Name, message);
logEvent.Properties.Add("Status", "");
logger.Log(logEvent);
}
示例15: Write
public void Write(LogLevel level, LogEvent logEvent)
{
LogBuilder fluent;
switch (level)
{
case LogLevel.Trace:
fluent = _logger.Trace();
break;
case LogLevel.Info:
fluent = _logger.Info();
break;
case LogLevel.Warning:
fluent = _logger.Warn();
break;
case LogLevel.Error:
fluent = _logger.Error();
break;
case LogLevel.Critical:
fluent = _logger.Fatal();
break;
default:
throw new ApplicationException("Invalid log level");
}
if (!string.IsNullOrWhiteSpace(logEvent.Message))
fluent.Message(logEvent.Message);
if (logEvent.Exception != null)
fluent.Exception(logEvent.Exception);
foreach (var parameter in logEvent.Parameters)
{
fluent.Property(parameter.Key, parameter.Value);
}
fluent.Write();
}