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 { /// /// NLog 扩展 /// public class LoggingProductionTarget: TargetWithLayout { static readonly int LOGVIEW_MAXLINE = 1000; private readonly LogDataService logDataService = LogDataService.Instance(); protected override void Write(LogEventInfo loggingEvent) { logDataService.LogProductionModels.Insert(0, new LoggingEventModel(loggingEvent)); if (logDataService.LogProductionModels.Count == LOGVIEW_MAXLINE) { logDataService.LogProductionModels.RemoveAt(LOGVIEW_MAXLINE - 1); } } } }