예제 #1
0
        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;
            }
        }
예제 #2
0
        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));
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
        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);
        }
예제 #5
0
        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();
                }
            }
        }
예제 #6
0
 public static extern int FlushTrace(ulong SessionHandle, string SessionName, ref EventTraceProperties Properties);
예제 #7
0
 public static extern int ControlTrace(ulong SessionHandle, string SessionName, ref EventTraceProperties Properties, uint ControlCode);
예제 #8
0
 public static extern int StartTrace(out ulong SessionHandle, [MarshalAs(UnmanagedType.LPWStr)] string SessionName, ref EventTraceProperties Properties);