コード例 #1
0
ファイル: TraceSession.cs プロジェクト: zmyer/service-fabric
        public void Open()
        {
            Guid localProviderId = this.providerInfo.Id;
            int  errorCode       = NativeMethods.EnableTraceEx(
                ref localProviderId,
                IntPtr.Zero,
                this.sessionHandle,
                1,
                this.providerInfo.Level,
                (ulong)this.providerInfo.Keywords,
                0,
                0,
                IntPtr.Zero);

            if (errorCode != 0)
            {
                throw new Win32Exception();
            }

            this.traceEnabled = true;
            EventTraceLogfile logFile = new EventTraceLogfile();

            logFile.ProcessTraceMode = TraceSession.ProcessTraceModeRealTime | TraceSession.ProcessTraceModeEventRecord;
            logFile.LoggerName       = this.sessionName;

            // The callback must be pinned to keep it in scope outside of this method
            EventRecordCallback callback = new EventRecordCallback(this.EventRecordCallback);

            this.callbackHandle         = GCHandle.Alloc(callback);
            logFile.EventRecordCallback = callback;

            this.traceHandle = NativeMethods.OpenTrace(ref logFile);
            if (this.traceHandle == InvalidHandle)
            {
                throw new Win32Exception();
            }
        }
コード例 #2
0
        private void InitializeTraceHandle()
        {
            if (traceHandle == 0)
            {
                this.eventTraceLogFile = new EventTraceLogfile
                {
                    ProcessTraceMode = TraceModeEventRecord,
                    LogFileName      = this.fileName
                };

                // wrap callback in GCHandle to prevent object from being garbage collected
                EventRecordCallback callback = this.EventRecordCallback;
                this.callbackHandle = GCHandle.Alloc(callback);
                this.eventTraceLogFile.EventRecordCallback = this.EventRecordCallback;

                this.traceHandle = NativeMethods.OpenTrace(ref eventTraceLogFile);
                if (this.traceHandle == InvalidHandle)
                {
                    throw new Win32Exception();
                }

                this.EventsLost = this.eventTraceLogFile.LogfileHeader.EventsLost;
            }
        }
コード例 #3
0
ファイル: NativeMethods.cs プロジェクト: zmyer/service-fabric
 public static extern ulong OpenTrace(ref EventTraceLogfile logfile);