為了方便廣大計算機愛好者,下面是小編整理的關於Log4net工程中的使用備忘,歡迎參考!
(1):引用log4net
(2):using log4net;
(3):構造函數中
static CoreLogging()
{
igure();
}
(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 = ogger(GeneralCategory);
private static ILog scriptLog = ogger(ScriptCategory);
private static ILog configLog = ogger(ConfigCategory);
private static ILog scanLog = ogger(ScanCategory);
private static ILog messageMergeLog = ogger(MessageMergeCategory);
private static ILog udpLog = ogger(UdpCategory);
private static ILog alarmLog = ogger(AlarmCategory);
private static ILog unknownDeviceLog = ogger(UnknownDeviceCategory);
private static void Log(ILog logger, Object message, Priority priority)
{
switch (priority)
{
case G:
g(message);
break;
case :
(message);
break;
case :
(message);
break;
case R:
r(message);
break;
case L:
l(message);
break;
}
}
public static void LogMessageMergeLog(object message, Priority priority)
{
Log(messageMergeLog, message, priority);
}
///
/// 通過Udp發送日誌
///
/// 要發送的.消息內容
/// 優先級
public static void SendLogViaUdp(object message, Priority priority)
{
Log(udpLog, message, priority);
}
其他的略。
配置文件中需要配置如下
其他略
下面為各個動作。Trace類型