LoggingProductionTarget.cs 863 B

12345678910111213141516171819202122232425262728293031
  1. using NLog;
  2. using NLog.Targets;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace SKMC.Api.Common.Logger
  9. {
  10. /// <summary>
  11. /// NLog 扩展
  12. /// </summary>
  13. [Target("LoggingProductionTarget")]
  14. public class LoggingProductionTarget: TargetWithLayout
  15. {
  16. static readonly int LOGVIEW_MAXLINE = 1000;
  17. private readonly LogDataService logDataService = LogDataService.Instance();
  18. protected override void Write(LogEventInfo loggingEvent)
  19. {
  20. logDataService.LogProductionModels.Insert(0, new LoggingEventModel(loggingEvent));
  21. if (logDataService.LogProductionModels.Count == LOGVIEW_MAXLINE)
  22. {
  23. logDataService.LogProductionModels.RemoveAt(LOGVIEW_MAXLINE - 1);
  24. }
  25. }
  26. }
  27. }