我想将NLog的用法添加到我的项目中,我认为有一个处理所有日志记录的静态类会很好。像这样的东西:
public static class NLogger
{
public static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public static void Info(string message, object obj = null)
{
string userId = "111111";
string agentId = "666666";
NLog.LogEventInfo info = new NLog.LogEventInfo(NLog.LogLevel.Info, logger.Name, message);
info.Properties["UserId"] = userId;
info.Properties["AgentId"] = agentId;
logger.Log(info);
}
public static void Debug(string message, object obj = null)
{
string userId = "111111";
string agentId = "666666";
NLog.LogEventInfo info = new NLog.LogEventInfo(NLog.LogLevel.Debug, logger.Name, message);
info.Properties["LoggedInUserId"] = userId;
info.Properties["LoggedInAgetnID"] = agentId;
logger.Log(info);
}
}
我知道NLog处理异步写入并且可以同时处理多个日志请求。 如上例所示包装NLog会损害其行为吗?