LogDataModel.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using GreenTree.Nachtragsmanagement.Core.Domain.Logging;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. namespace GreenTree.Nachtragsmanagement.Web.Models.Misc
  7. {
  8. public class LogDataModel
  9. {
  10. public int Id { get; set; }
  11. public int LogLevelId { get; set; }
  12. public string LogLevelDescription { get; set; }
  13. public string ShortMessage { get; set; }
  14. public string FullMessage { get; set; }
  15. public string IpAddress { get; set; }
  16. public int? UserId { get; set; }
  17. public string UserDescription { get; set; }
  18. public int? EntityId { get; set; }
  19. public string EntityType { get; set; }
  20. public string PageUrl { get; set; }
  21. public string ReferrerUrl { get; set; }
  22. public DateTime CreatedOnUtc { get; set; }
  23. public LogDataModel()
  24. {
  25. }
  26. public static LogDataModel FromLog(Core.Domain.Logging.Log logEntity, bool newWhenIsNull)
  27. {
  28. if (logEntity == null && newWhenIsNull)
  29. return new LogDataModel
  30. {
  31. Id = -1,
  32. };
  33. if (logEntity == null && !newWhenIsNull)
  34. throw new ArgumentNullException("logEntity", "Cannot create LogDataModel from NULL log entity.");
  35. var logDataModel = new LogDataModel
  36. {
  37. Id = logEntity.Id,
  38. LogLevelId = logEntity.LogLevelId,
  39. LogLevelDescription = Enum.GetName(typeof(LogLevel), (LogLevel)logEntity.LogLevelId),
  40. ShortMessage = logEntity.ShortMessage,
  41. FullMessage = logEntity.FullMessage,
  42. IpAddress = logEntity.IpAddress,
  43. UserId = logEntity.UserId,
  44. UserDescription = logEntity.User == null
  45. ? String.Empty
  46. : logEntity.User.Lastname,
  47. EntityId = logEntity.EntityId,
  48. EntityType = logEntity.EntityType,
  49. PageUrl = logEntity.PageUrl,
  50. ReferrerUrl = logEntity.ReferrerUrl,
  51. CreatedOnUtc = logEntity.CreatedOnUtc
  52. };
  53. return logDataModel;
  54. }
  55. }
  56. }