LogDataModel.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 DateTime CreatedOnLocal
  24. {
  25. get
  26. {
  27. return CreatedOnUtc.ToLocalTime();
  28. }
  29. }
  30. public LogDataModel()
  31. {
  32. }
  33. public static LogDataModel FromLog(Core.Domain.Logging.Log logEntity, bool newWhenIsNull)
  34. {
  35. if (logEntity == null && newWhenIsNull)
  36. return new LogDataModel
  37. {
  38. Id = -1,
  39. };
  40. if (logEntity == null && !newWhenIsNull)
  41. throw new ArgumentNullException("logEntity", "Cannot create LogDataModel from NULL log entity.");
  42. var logDataModel = new LogDataModel
  43. {
  44. Id = logEntity.Id,
  45. LogLevelId = logEntity.LogLevelId,
  46. LogLevelDescription = Enum.GetName(typeof(LogLevel), (LogLevel)logEntity.LogLevelId),
  47. ShortMessage = logEntity.ShortMessage,
  48. FullMessage = logEntity.FullMessage,
  49. IpAddress = logEntity.IpAddress,
  50. UserId = logEntity.UserId,
  51. UserDescription = logEntity.User == null
  52. ? String.Empty
  53. : logEntity.User.Lastname,
  54. EntityId = logEntity.EntityId,
  55. EntityType = logEntity.EntityType,
  56. PageUrl = logEntity.PageUrl,
  57. ReferrerUrl = logEntity.ReferrerUrl,
  58. CreatedOnUtc = logEntity.CreatedOnUtc
  59. };
  60. return logDataModel;
  61. }
  62. }
  63. }