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 static EventTraceProperties CreateProperties(Guid sessionId, bool createForQuery) { EventTraceProperties properties = new EventTraceProperties(); properties.Wnode = new EventTraceProperties.WnodeHeader(); properties.Wnode.BufferSize = (uint)TraceSession.EventTracePropertiesSize; properties.Wnode.Flags = TraceSession.WnodeFlagTracedGuid; properties.Wnode.Guid = sessionId; properties.FlushTimer = 0; properties.LogFileMode = createForQuery ? 0 : TraceSession.EventTraceRealTimeMode; properties.LoggerNameOffset = (uint)(TraceSession.EventTracePropertiesSize - (Marshal.SystemDefaultCharSize * (EventTraceProperties.MaxLoggerNameLength + EventTraceProperties.MaxLogFileNameLength))); properties.LogFileNameOffset = (uint)(TraceSession.EventTracePropertiesSize - (Marshal.SystemDefaultCharSize * EventTraceProperties.MaxLogFileNameLength)); return(properties); }
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(); } } }
public static extern int FlushTrace(ulong SessionHandle, string SessionName, ref EventTraceProperties Properties);
public static extern int ControlTrace(ulong SessionHandle, string SessionName, ref EventTraceProperties Properties, uint ControlCode);
public static extern int StartTrace(out ulong SessionHandle, [MarshalAs(UnmanagedType.LPWStr)] string SessionName, ref EventTraceProperties Properties);