我试图了解使用Windows.Foundation.Diagnostics.LoggingChannel
的正确方法。特别是我想了解Level
属性背后的目的以及何时设置此属性。
如LoggingChannel
的{{3}}所述,Level
属性是只读的。那么如何设置频道接受消息的级别?
目前我设计的应用程序记录器如下所示:
public class Logger
{
public LoggingLevel LoggerLoggingLevel { get; set; }
private LoggingSession _session;
private LoggingChannel _channel;
public Logger()
{
_channel = new LoggingChannel("MyChannel");
_session = new LoggingSession("MySession");
_session.AddLoggingChannel(_channel);
}
public void LogMessage(string msg, LoggingLevel level)
{
if (level >= LoggerLoggingLevel)
{
_channel.LogMessage(msg, level);
}
}
.
.
.
}
// The consumer of the Logger class will instantiate an instance of it,
// sets the LoggerLoggingLevel, and then starts logging messages at various levels.
// At any point, the consumer can change LoggerLoggingLevel to start accepting
// messages at different levels.
这是正确的方法还是有更好的方法(例如以某种方式设置_channel
的级别,然后将消息&级别传递给频道,让频道决定是否应过滤掉消息或接受并记录它?)