| 12345678910111213141516171819202122232425262728293031 |
- using NLog;
- using NLog.Targets;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SKMC.Api.Common.Logger
- {
- /// <summary>
- /// NLog 扩展
- /// </summary>
- [Target("LoggingActionTarget")]
- public class LoggingActionTarget : TargetWithLayout
- {
- static readonly int LOGVIEW_MAXLINE = 1000;
- private readonly LogDataService logDataService = LogDataService.Instance();
- protected override void Write(LogEventInfo loggingEvent)
- {
- logDataService.LogActionModels.Insert(0, new LoggingEventModel(loggingEvent));
- if (logDataService.LogActionModels.Count == LOGVIEW_MAXLINE)
- {
- logDataService.LogActionModels.RemoveAt(LOGVIEW_MAXLINE - 1);
- }
- }
- }
- }
|