public static IDisposable StartLineTracking(IServiceProvider serviceProvider, string scope = null, [CallerFilePath] string filePath = null, int lineNumber = 0, [CallerMemberName] string caller = null) { #if ENABLE_LINE_TRACKING LineTracker lineTracker; var key = scope ?? filePath; if (Trackers == null) { Trackers = new FixedDictionary <string, LineTracker>(100); } if (!Trackers.ContainsKey(key)) { lineTracker = new LineTracker(scope, filePath, serviceProvider); Trackers.Add(key, lineTracker); } else { lineTracker = Trackers[key]; } TrackLine(filePath, lineNumber, caller); return(lineTracker.AsDisposable(() => { if (lineTracker.PrimaryFilePath == filePath) { Trackers.Remove(filePath); } })); #else return(typeof(DebugUtils).AsDisposable(() => { })); #endif }
public TraceLogEventSink(string ipAddress, int port, CancellationToken cancellationToken, TraceLogEventSinkConfigArgs traceLogEventSinkConfigArgs = null) : base() { queuedEvents = new FixedDictionary <LogEvent, LogEvent>(NumberExtensions.MB); this.Address = ipAddress; this.Port = port; this.CancellationToken = cancellationToken; this.traceLogEventSinkConfigArgs = traceLogEventSinkConfigArgs; this.ID = Guid.NewGuid().ToString(); this.Start(); cancellationToken.Register(() => { this.Stop(); }); }
public LoggerRelayEventSink(ILoggerRelay loggerRelay, CancellationToken cancellationToken, LoggerRelayEventSinkConfigArgs loggerRelayEventSinkConfigArgs = null) : base(ThreadPriority.Highest, 100) { bool mutexCreated; var outputTemplate = "{Timestamp:yyyy-MM-dd hh:mm:ss.fff} [{Level}] {SourceContext} {Message}"; DateTime.Now.ToDebugDateText(); this.Domain = loggerRelay.Domain; this.RootPath = Environment.ExpandEnvironmentVariables(loggerRelayEventSinkConfigArgs.RootPath); this.CancellationToken = cancellationToken; this.ID = Guid.NewGuid().ToString(); try { mutex = Mutex.OpenExisting(string.Format(@"Global\{0}+Mutex", this.Domain)); } catch { mutex = new Mutex(false, string.Format(@"Global\{0}+Mutex", this.Domain), out mutexCreated); } this.loggerRelayEventSinkConfigArgs = loggerRelayEventSinkConfigArgs; this.loggerRelay = loggerRelay; this.formatter = new MessageTemplateTextFormatter(outputTemplate); this.queuedEvents = new FixedDictionary <LoggerRelayEvent, LogEvent>(NumberExtensions.MB); if (loggerRelayEventSinkConfigArgs != null) { if (!loggerRelayEventSinkConfigArgs.Enabled) { return; } captureStack = loggerRelayEventSinkConfigArgs.CaptureStack.Where(c => c.Enabled).ToDictionary(c => c.Log, c => c.Assemblies.Where(a => a.Enabled).ToDictionary(a => a.Assembly, a => a)); } this.Start(); cancellationToken.Register(() => { this.Stopped = true; }); }