コード例 #1
0
ファイル: TraceSession.cs プロジェクト: zmyer/service-fabric
        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
ファイル: TraceSession.cs プロジェクト: zmyer/service-fabric
        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
ファイル: TraceSession.cs プロジェクト: zmyer/service-fabric
        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
ファイル: TraceSession.cs プロジェクト: zmyer/service-fabric
        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
ファイル: TraceSession.cs プロジェクト: zmyer/service-fabric
        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
ファイル: NativeMethods.cs プロジェクト: zmyer/service-fabric
 public static extern int FlushTrace(ulong SessionHandle, string SessionName, ref EventTraceProperties Properties);
コード例 #7
0
ファイル: NativeMethods.cs プロジェクト: zmyer/service-fabric
 public static extern int ControlTrace(ulong SessionHandle, string SessionName, ref EventTraceProperties Properties, uint ControlCode);
コード例 #8
0
ファイル: NativeMethods.cs プロジェクト: zmyer/service-fabric
 public static extern int StartTrace(out ulong SessionHandle, [MarshalAs(UnmanagedType.LPWStr)] string SessionName, ref EventTraceProperties Properties);