private unsafe uint ClassicControlCallback(ClassicEtw.WMIDPREQUESTCODE requestCode, IntPtr requestContext, IntPtr reserved, ClassicEtw.WNODE_HEADER *data)
        {
            int  traceEnableFlags = ClassicEtw.GetTraceEnableFlags(data.HistoricalContext);
            byte traceEnableLevel = ClassicEtw.GetTraceEnableLevel(data.HistoricalContext);
            int  isEnabled        = 0;

            if (requestCode == ClassicEtw.WMIDPREQUESTCODE.EnableEvents)
            {
                this.m_classicSessionHandle = ClassicEtw.GetTraceLoggerHandle(data);
                isEnabled = 1;
            }
            else if (requestCode == ClassicEtw.WMIDPREQUESTCODE.DisableEvents)
            {
                this.m_classicSessionHandle = 0L;
                isEnabled = 0;
            }
            this.m_etwCallback(ref this.m_providerId, isEnabled, traceEnableLevel, (long)traceEnableFlags, 0L, null, null);
            return(0);
        }
Beispiel #2
0
        //
        // This callback function is called by ETW to enable or disable this provider
        //
        private unsafe uint EtwEnableCallback(ClassicEtw.WMIDPREQUESTCODE requestCode, IntPtr context, IntPtr bufferSize, ClassicEtw.WNODE_HEADER *buffer)
        {
            try
            {
                switch (requestCode)
                {
                case ClassicEtw.WMIDPREQUESTCODE.EnableEvents:
                    _traceHandle = buffer->HistoricalContext;
                    _keywords    = (EventTrace.Keyword)ClassicEtw.GetTraceEnableFlags((ulong)buffer->HistoricalContext);
                    _level       = (EventTrace.Level)ClassicEtw.GetTraceEnableLevel((ulong)buffer->HistoricalContext);
                    _enabled     = true;
                    break;

                case ClassicEtw.WMIDPREQUESTCODE.DisableEvents:
                    _enabled     = false;
                    _traceHandle = 0;
                    _level       = EventTrace.Level.LogAlways;
                    _keywords    = 0;
                    break;

                default:
                    _enabled     = false;
                    _traceHandle = 0;
                    break;
                }
                return(0);
            }
            catch (Exception e)
            {
                if (CriticalExceptions.IsCriticalException(e))
                {
                    throw;
                }
                else
                {
                    return(0);
                }
            }
        }