定義通道

事件可以寫入事件記錄檔通道、事件追蹤記錄檔或兩者。 通道基本上是收集事件的接收。 如果事件的目標物件使用 Windows 事件檢視器之類的事件取用者,您必須定義新的通道來收集事件,或匯入另一個提供者定義的現有通道。

若要定義您自己的通道,請使用 channel 元素。 若要定義匯入的通道,請使用 importChannel 元素。 您可以在您所定義之匯入通道或通道的任何組合中指定最多八個通道。

通道必須是四種類型之一:管理員、操作、分析和偵錯。 每個通道類型都有預定的物件,可決定您寫入通道的事件種類。 如需每種類型的描述,請參閱 ChannelType 複雜類型。

若要指定寫入事件的通道,請將事件定義的 通道 屬性設定為與通道定義的 chid 屬性相同的值。 事件一次只能寫入一個通道,但也可以同時由最多 7 個其他 ETW 會話收集。

下列範例示範如何匯入通道。 您必須設定 chidname 屬性。 chid屬性可唯一識別通道—通道清單中的每個通道識別碼都必須是唯一的。 將 name 屬性設定為提供者在定義通道時所使用的相同名稱。

<instrumentationManifest
    xmlns="http://schemas.microsoft.com/win/2004/08/events" 
    xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    >

    <instrumentation>
        <events>
            <provider name="Microsoft-Windows-SampleProvider" 
                guid="{1db28f2e-8f80-4027-8c5a-a11f7f10f62d}" 
                symbol="PROVIDER_GUID" 
                resourceFileName="<path to the exe or dll that contains the metadata resources>" 
                messageFileName="<path to the exe or dll that contains the string resources>"
                message="$(string.Provider.Name)">

                <channels>
                    <channel chid="c1"
                             name="Microsoft-Windows-BaseProvider/Admin"
                             symbol="CHANNEL_BASEPROVIDER_ADMIN"
                             type="Admin"/>
                </channels>

                . . .

            </provider>
        </events>
    </instrumentation>

    <localization>
        <resources culture="en-US">
            <stringTable>
                <string id="Provider.Name" value="Microsoft-Windows-SampleProvider"/>
            </stringTable>
        </resources>
    </localization>

</instrumentationManifest>

雖然Winmeta.xml定義您可以匯入的舊版通道,除非您支援舊版取用者取用舊版通道的事件, (例如應用程式或系統) ,否則請勿使用這些通道。 Winmeta.xml檔案包含在 Windows SDK 中。

下列範例示範如何定義通道。 您必須設定 chidnametype 屬性。 chid屬性可唯一識別通道—通道清單中的每個通道識別碼都必須是唯一的。 將 chid 屬性設定為提供者所列出通道的唯一值;通道識別碼會在一或多個事件定義中參考。 命名通道的慣例是使用提供者名稱和通道類型,格式為providername/channeltype

<instrumentationManifest
    xmlns="http://schemas.microsoft.com/win/2004/08/events" 
    xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    >

    <instrumentation>
        <events>
            <provider name="Microsoft-Windows-SampleProvider"
                guid="{1db28f2e-8f80-4027-8c5a-a11f7f10f62d}"
                symbol="PROVIDER_GUID"
                resourceFileName="<path to the exe or dll that contains the metadata resources>"
                messageFileName="<path to the exe or dll that contains the string resources>"
                message="$(string.Provider.Name)">

                <channels>
                    <importChannel chid="c1"
                                   name="Microsoft-Windows-BaseProvider/Admin"
                                   symbol="CHANNEL_BASEPROVIDER_ADMIN"
                                   />

                    <channel chid="c2"
                             name="Microsoft-Windows-SampleProvider/Operational"
                             type="Operational"
                             enabled="true"
                             />
                </channels>

                . . .

            </provider>
        </events>
    </instrumentation>

    <localization>
        <resources culture="en-US">
            <stringTable>
                <string id="Provider.Name" value="Microsoft-Windows-SampleProvider"/>
            </stringTable>
        </resources>
    </localization>

</instrumentationManifest>