public RealTimeEventReader(string name, ProviderInfo providerInfo, TimeSpan flushInterval) { if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException(StringResources.ETLReaderError_EmptyParameter, "name"); } int max = EventTraceProperties.MaxLoggerNameLength - 1; if (name.Length > max) { throw new ArgumentOutOfRangeException("name", String.Format(System.Globalization.CultureInfo.CurrentCulture, StringResources.ETLReaderError_ParameterExceedsMax_Formatted, max) ); } if (providerInfo == null) { throw new ArgumentNullException("providerInfo"); } if (flushInterval < TimeSpan.Zero) { throw new ArgumentOutOfRangeException("flushInterval"); } this.rwLock = new ReaderWriterLockSlim(); this.traceSession = new TraceSession(name, providerInfo, flushInterval); }
private void OnTimerElapsed(object sender) { EventTraceProperties properties = TraceSession.CreateProperties(this.sessionId, false); if (NativeMethods.FlushTrace(this.sessionHandle, this.sessionName, ref properties) == 0) { this.EventsLost = properties.EventsLost; } }
public static string GetLogFilePath(string traceSessionName) { EventTraceProperties properties = TraceSession.CreateProperties(Guid.Empty, true); int errorCode = NativeMethods.ControlTrace(0, traceSessionName, ref properties, TraceSession.EventTraceControlQuery); if (errorCode != 0) { throw new Win32Exception(errorCode); } return(Path.GetDirectoryName(properties.LogFileName)); }
public TraceSession(string name, ProviderInfo providerInfo, TimeSpan flushInterval) { this.providerInfo = providerInfo; this.flushInterval = flushInterval; this.sessionId = Guid.NewGuid(); this.sessionName = name; EventTraceProperties properties = TraceSession.CreateProperties(this.sessionId, false); int errorCode = NativeMethods.StartTrace(out this.sessionHandle, this.sessionName, ref properties); if (errorCode != 0) { throw new Win32Exception(); } }
private void DisposeTraceSession() { if (this.traceSession != null) { this.rwLock.EnterWriteLock(); try { this.traceSession.Dispose(); this.traceSession = null; } finally { this.rwLock.ExitWriteLock(); } } }
private void Dispose(bool disposing) { if (this.traceHandle != TraceSession.InvalidHandle) { NativeMethods.CloseTrace(this.traceHandle); this.traceHandle = TraceSession.InvalidHandle; } if (this.traceEnabled) { Guid localProviderId = this.providerInfo.Id; NativeMethods.EnableTraceEx( ref localProviderId, IntPtr.Zero, this.sessionHandle, 0, 0, 0, 0, 0, IntPtr.Zero); this.traceEnabled = false; } if (this.sessionHandle != 0) { EventTraceProperties properties = TraceSession.CreateProperties(this.sessionId, false); NativeMethods.ControlTrace(this.sessionHandle, null, ref properties, TraceSession.EventTraceControlStop); this.sessionHandle = 0; } if (disposing) { if (this.callbackHandle.IsAllocated) { this.callbackHandle.Free(); } } }