- 相關(guān)推薦
關(guān)于Log4net工程使用備忘
為了方便廣大計(jì)算機(jī)愛(ài)好者,下面是小編整理的關(guān)于Log4net工程中的使用備忘,歡迎參考!
(1):引用log4net
(2):using log4net;
(3):構(gòu)造函數(shù)中
static CoreLogging()
{
log4net.Config.XmlConfigurator.Configure();
}
(4):private const string UnknownDeviceCategory = "UnknownDevice";
private const string AlarmCategory = "Alarm";
private const string GeneralCategory = "Trace";
private const string ScriptCategory = "Script";
private const string ConfigCategory = "Config";
private const string ScanCategory = "Scan";
private const string UdpCategory = "UdpSender";
private const string MessageMergeCategory = "MessageMerge";
private static ILog traceLog = LogManager.GetLogger(GeneralCategory);
private static ILog scriptLog = LogManager.GetLogger(ScriptCategory);
private static ILog configLog = LogManager.GetLogger(ConfigCategory);
private static ILog scanLog = LogManager.GetLogger(ScanCategory);
private static ILog messageMergeLog = LogManager.GetLogger(MessageMergeCategory);
private static ILog udpLog = LogManager.GetLogger(UdpCategory);
private static ILog alarmLog = LogManager.GetLogger(AlarmCategory);
private static ILog unknownDeviceLog = LogManager.GetLogger(UnknownDeviceCategory);
private static void Log(ILog logger, Object message, Priority priority)
{
switch (priority)
{
case Priority.DEBUG:
logger.Debug(message);
break;
case Priority.INFO:
logger.Info(message);
break;
case Priority.WARN:
logger.Warn(message);
break;
case Priority.ERROR:
logger.Error(message);
break;
case Priority.FATAL:
logger.Fatal(message);
break;
}
}
public static void LogMessageMergeLog(object message, Priority priority)
{
Log(messageMergeLog, message, priority);
}
///
/// 通過(guò)Udp發(fā)送日志
///
/// 要發(fā)送的消息內(nèi)容
/// 優(yōu)先級(jí)
public static void SendLogViaUdp(object message, Priority priority)
{
Log(udpLog, message, priority);
}
其他的略。
配置文件中需要配置如下
其他略
下面為各個(gè)動(dòng)作。Trace類型
【Log4net工程使用備忘】相關(guān)文章:
工程機(jī)械使用壽命探討06-15
BEC中級(jí)寫作指導(dǎo):備忘錄的寫法10-12
商務(wù)英語(yǔ)中的備忘錄怎么寫09-29
鍋蓋使用技巧-如何使用鍋蓋10-29
2017年小升初每月大事備忘錄07-28