星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

LogHelper.cs 1.0KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using log4net.Config;
  2. using System;
  3. using System.IO;
  4. namespace Common.system
  5. {
  6. public class LogHelper
  7. {
  8. public static readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("loginfo");
  9. public static readonly log4net.ILog logerror = log4net.LogManager.GetLogger("logerror");
  10. public static void InitLog4Net()
  11. {
  12. var logCfg = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config");
  13. XmlConfigurator.ConfigureAndWatch(logCfg);
  14. loginfo.Info("日志初始化");
  15. }
  16. public static void WriteInfoLog(string info)
  17. {
  18. if (loginfo.IsInfoEnabled)
  19. {
  20. loginfo.Info(info);
  21. Console.WriteLine(info);
  22. }
  23. }
  24. public static void WriteErrLog(string info, Exception ex)
  25. {
  26. if (logerror.IsErrorEnabled)
  27. {
  28. logerror.Error("[V " + FileToolsCommon.GetConfigValue("VersionName") + "]" + info, ex);
  29. }
  30. }
  31. }
  32. }