关于Log4net工程使用备忘

发布时间:2016-11-07 00:00:00 编辑:嘉辉 手机版

  为了方便广大计算机爱好者,下面是小编整理的关于Log4net工程中的使用备忘,欢迎参考!

  (1):引用log4net

  (2):using log4net;

  (3):构造函数中

  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);

  }

  ///

  /// 通过Udp发送日志

  ///

  /// 要发送的消息内容

  /// 优先级

  public static void SendLogViaUdp(object message, Priority priority)

  {

  Log(udpLog, message, priority);

  }

  其他的略。

  配置文件中需要配置如下

  其他略

  下面为各个动作。Trace类型

本文已影响866
+1
0