2 回答
TA贡献1818条经验 获得超3个赞
感谢您的评论和回答。Severius5,您的回答(现在已删除?)给了我答案。这段代码做我需要的:
var rules = NLog.LogManager.Configuration.LoggingRules;
var rule = rules.FirstOrDefault(x => x.LoggerNamePattern == "hostLogger");
NLog.LogManager.GetLogger("hostLogger").Info("Minimum Log Level: {0}", rule.Levels.Min());
它在日志中给了我这个输出:
2018-08-03 14:26:11.7439 | 信息 | 最低日志级别:调试
TA贡献1836条经验 获得超3个赞
也许是这样的:
var logger = NLog.LogManager.GetLogger("hostLogger");
var minLogLevel = "Disabled";
if (logger.IsTraceEnabled)
minLogLevel = "Trace";
else if (logger.IsDebugEnabled)
minLogLevel = "Debug";
else if (logger.IsInfoEnabled)
minLogLevel = "Info";
else if (logger.IsWarnEnabled)
minLogLevel = "Warn";
else if (logger.IsErrorEnabled)
minLogLevel = "Error";
else if (logger.IsFatalEnabled)
minLogLevel = "Fatal";
logger.Info("Minimum Log Level: {0}", minLogLevel)
- 2 回答
- 0 关注
- 163 浏览
添加回答
举报