LogConfig_t.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace IACommService4CSharp
  7. {
  8. enum LevelMask_t
  9. {
  10. LOG_LEVEL_FATAL = 0x00000001,
  11. LOG_LEVEL_ERROR = 0x00000002,
  12. LOG_LEVEL_WARN = 0x00000004,
  13. LOG_LEVEL_INFO = 0x00000008
  14. }
  15. enum CategoryMask_t
  16. {
  17. LOG_CATEGORY_SYSTEM = 0x00000001,
  18. LOG_CATEGORY_CONNECT = 0x00000002,
  19. LOG_CATEGORY_READ = 0x00000004,
  20. LOG_CATEGORY_WRITE = 0x00000008,
  21. LOG_CATEGORY_SUBSCRIBE = 0x00000010
  22. }
  23. public class LogConfig_t
  24. {
  25. private static readonly string Service_Log_Enable = "LogEnable";
  26. private static readonly string Service_Log_Path = "LogPath";
  27. private static readonly string Service_Log_DateFormat = "LogDateFormat";
  28. private static readonly string Service_Log_MaxFileSize = "LogMaxFileSize";
  29. private static readonly string Service_Log_MaxBackupIndex = "LogMaxBackupIndex";
  30. private static readonly string Service_Log_LevelMask = "LogLevelMask";
  31. private static readonly string Service_Log_CategoryMask = "LogCategoryMask";
  32. public LogConfig_t()
  33. {
  34. Enable = true;
  35. Path = "./";
  36. DateFormat = "%Y-%m-%d %H:%M:%S.%q";
  37. MaxFileSize = 524288;
  38. MaxBackupIndex = 5;
  39. LevelMask = Convert.ToUInt32(LevelMask_t.LOG_LEVEL_FATAL | LevelMask_t.LOG_LEVEL_ERROR | LevelMask_t.LOG_LEVEL_WARN | LevelMask_t.LOG_LEVEL_INFO);
  40. CategoryMask = Convert.ToUInt32(CategoryMask_t.LOG_CATEGORY_SYSTEM | CategoryMask_t.LOG_CATEGORY_CONNECT);
  41. }
  42. ~LogConfig_t()
  43. {
  44. }
  45. public bool Enable { get; set; }
  46. public string Path { get; set; }
  47. public string DateFormat { get; set; }
  48. public uint MaxFileSize { get; set; }
  49. public uint MaxBackupIndex { get; set; }
  50. public uint LevelMask { get; set; }
  51. public uint CategoryMask { get; set; }
  52. //Internal use
  53. public Dictionary<string, string> GetConfig()
  54. {
  55. Dictionary<string, string> logConfig = new Dictionary<string, string>();
  56. logConfig.Add(Service_Log_Enable, Enable ? "true" : "false");
  57. logConfig.Add(Service_Log_Path, Path);
  58. logConfig.Add(Service_Log_DateFormat, DateFormat);
  59. logConfig.Add(Service_Log_MaxFileSize, Convert.ToString(MaxFileSize));
  60. logConfig.Add(Service_Log_MaxBackupIndex, Convert.ToString(MaxBackupIndex));
  61. logConfig.Add(Service_Log_LevelMask, Convert.ToString(LevelMask));
  62. logConfig.Add(Service_Log_CategoryMask, Convert.ToString(CategoryMask));
  63. return logConfig;
  64. }
  65. }
  66. }