﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="DiagnosticsConfigSchema"
    targetNamespace="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration"
    elementFormDefault="qualified"
    xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration"
    xmlns:wad="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration"
    xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:simpleType name="PositiveDuration">
    <xs:restriction base="xs:duration">
      <xs:minInclusive value="PT0S" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="LogLevel">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Undefined" />
      <xs:enumeration value="Verbose" />
      <xs:enumeration value="Information" />
      <xs:enumeration value="Warning" />
      <xs:enumeration value="Error" />
      <xs:enumeration value="Critical" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="ContainerName">
    <xs:restriction base="xs:string">
      <!-- 
       container can be between 3 to 63 chars. a char can be a lower case letter or digit or a '-' 
       There cannot be 2 consecutive '-' and it cannot start or end with '-'
       -->
      <xs:minLength value="3"/>
      <xs:maxLength value="63"/>
      <xs:pattern  value="[a-z0-9]+(\-([a-z0-9])+)*[a-z0-9]*" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="HexOrInteger">
    <xs:restriction base="xs:string">
      <xs:pattern value="(0[xX][0-9a-fA-F]+)|([0-9]+)" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="locale">
    <xs:restriction base="xs:string">
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="displayName">
    <xs:restriction base="xs:string">
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="AbsolutePathWithEnvironmentExpansion">
    <xs:restriction base="xs:string">
      <xs:pattern value="([a-zA-Z]:\\)?([^&lt;&gt;:&quot;/|?*]+)*(\\)?" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="RelativePathWithEnvironmentExpansion">
    <xs:restriction base="xs:string">
      <xs:pattern value="([^&lt;&gt;:&quot;/\\|?*]+)(\\([^&lt;&gt;:&quot;/\\|?*]+))*(\\)?" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="PerformanceCounterPath">
    <xs:restriction base="xs:string">
      <xs:pattern value="\\.*" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="EventNameType">
    <xs:restriction base="xs:string">
      <xs:pattern value="[a-zA-Z][a-zA-Z0-9]{0,59}" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="CrashDumpType" >
    <xs:restriction base="xs:string">
      <xs:enumeration value="Mini"/>
      <xs:enumeration value="Full"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="NamedElementNameString">
    <xs:restriction base="xs:string">
      <xs:pattern value="^[a-zA-Z_][^\\\/\:\*\?\&quot;\&lt;\&gt;\|]*(?&lt;![\.\s])$" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="format">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Manifest" />
      <xs:enumeration value="EventSource" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="directoryQuotaPercentage">
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="0"/>
      <xs:maxInclusive value="100"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="guidType">
    <xs:annotation>
      <xs:documentation>
        A GUID. Brackets (and only brackets) before and/or after are ignored. e.g. {12345678-1234-1234-1234-123456789abc}, {12345678-1234-1234-1234-123456789abc, 12345678-1234-1234-1234-123456789abc} and 12345678-1234-1234-1234-123456789abc are valid.
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:pattern value="^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="sinkName">
    <xs:annotation>
      <xs:documentation>
        Non empty string with no commas allowed
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <!-- Must be a non empty string without commas, dots and spaces-->
      <xs:pattern value="[^,\. ]+" />
    </xs:restriction>
  </xs:simpleType>

  <xs:attributeGroup name="SinksAttribute">
    <xs:attribute name="sinks" type="xs:string">
      <xs:annotation>
        <xs:documentation>
          A comma separated list of channels and sinks to which data needs to be sent.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:attributeGroup>

  <xs:attributeGroup name="BasicConfiguration">
    <xs:attribute name="scheduledTransferPeriod" type="PositiveDuration" use="optional" default="PT0S">
      <xs:annotation>
        <xs:documentation>
          The interval between scheduled transfers for this data, rounded up to the nearest minute.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:attributeGroup>

  <xs:attributeGroup name="ETWConfiguration">
    <xs:attribute name="scheduledTransferLogLevelFilter" type="LogLevel" use="optional" default="Undefined">
      <xs:annotation>
        <xs:documentation>
          The minimum log severity to transfer.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="provider" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>
          The provider guid or class name for event source
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="scheduledTransferKeywordFilter" type="HexOrInteger" use="optional" default="0" >
      <xs:annotation>
        <xs:documentation>
          The keyword to filter by
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:attributeGroup>


  <xs:attributeGroup name="LogLevel">
    <xs:attribute name="scheduledTransferLogLevelFilter" type="LogLevel" use="optional" default="Undefined">
      <xs:annotation>
        <xs:documentation>
          The minimum log severity to transfer.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:attributeGroup>

  <xs:attributeGroup name="DirectoryAttributes">
    <xs:attribute name="containerName" type="wad:ContainerName" use="required">
      <xs:annotation>
        <xs:documentation>
          The name of the container where the content of the directory is to be transferred.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:attributeGroup>

  <xs:attributeGroup name="CrashDumpConfiguration">
    <xs:attribute name="directoryQuotaPercentage" type="directoryQuotaPercentage" use="optional" default="10">
      <xs:annotation>
        <xs:documentation>
          The percentage of directory quota used by crashdumps
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="dumpType" type="CrashDumpType" use="optional" default="Mini">
      <xs:annotation>
        <xs:documentation>
          The type of crashdump
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="containerName" type="wad:ContainerName" use="optional" default="wad-crashdumps">
      <xs:annotation>
        <xs:documentation>
          The blob container to store the crashdumps
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:attributeGroup>

  <xs:complexType name="LogsBase">
    <xs:attributeGroup ref="BasicConfiguration" />
  </xs:complexType>

  <xs:complexType name="LogsBaseWithSinks">
    <xs:attributeGroup ref="BasicConfiguration" />
    <xs:attributeGroup ref="SinksAttribute" />
  </xs:complexType>

  <xs:complexType name="EtwEventsBase">
    <xs:attributeGroup ref="ETWConfiguration" />
    <xs:attributeGroup ref="BasicConfiguration" />
    <xs:attributeGroup ref="SinksAttribute" />
  </xs:complexType>

  <xs:complexType name ="CrashDumpsBase">
    <xs:attributeGroup ref="CrashDumpConfiguration"/>
  </xs:complexType>

  <xs:complexType name="EtwManifestProviderConfiguration">
    <xs:complexContent>
      <xs:extension base="EtwEventsBase">
        <xs:sequence>
          <xs:element maxOccurs="unbounded" name="Event" minOccurs="0">
            <xs:complexType>
              <xs:attribute name="id" type="xs:int" use="required">
                <xs:annotation>
                  <xs:documentation>
                    The id of the ETW event that is to be collected
                  </xs:documentation>
                </xs:annotation>
              </xs:attribute>
              <xs:attribute name="eventDestination" type="EventNameType" use="optional">
                <xs:annotation>
                  <xs:documentation>
                    The name of the table in which the event data will be stored. If this attribute is not defined the table's name is 'Event'+'MD5 of the provider'+EventId#.
                  </xs:documentation>
                </xs:annotation>
              </xs:attribute>
              <xs:attributeGroup ref="SinksAttribute" />
            </xs:complexType>
          </xs:element>
          <xs:element name="DefaultEvents" minOccurs="0" maxOccurs="1">
            <xs:complexType>
              <xs:attribute name="eventDestination" type="EventNameType" use="optional">
                <xs:annotation>
                  <xs:documentation>
                    The name of the table in which the event data will be stored. If this attribute is not defined the table's name is 'Default'+'MD5 of the provider'+EventId#.
                  </xs:documentation>
                </xs:annotation>
              </xs:attribute>
              <xs:attributeGroup ref="SinksAttribute" />
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="EtwEventSourceProviderConfiguration">
    <xs:complexContent>
      <xs:extension base="EtwEventsBase">
        <xs:sequence>
          <xs:element maxOccurs="unbounded" name="Event" minOccurs="0">
            <xs:complexType>
              <xs:attribute name="id" type="xs:int" use="required">
                <xs:annotation>
                  <xs:documentation>
                    The id of the ETW event that is to be collected
                  </xs:documentation>
                </xs:annotation>
              </xs:attribute>
              <xs:attribute name="eventDestination" type="EventNameType" use="optional">
                <xs:annotation>
                  <xs:documentation>
                    The name of the table in which the event data will be stored. If this attribute is not defined the table's name is 'Event'+'MD5 of the provider'+EventId#.
                  </xs:documentation>
                </xs:annotation>
              </xs:attribute>
              <xs:attributeGroup ref="SinksAttribute" />
            </xs:complexType>
          </xs:element>
          <xs:element name="DefaultEvents" minOccurs="0" maxOccurs="1">
            <xs:complexType>
              <xs:attribute name="eventDestination" type="EventNameType" use="optional">
                <xs:annotation>
                  <xs:documentation>
                    The name of the table in which the event data will be stored. If this attribute is not defined the table's name is 'Default'+'MD5 of the provider'+EventId#.
                  </xs:documentation>
                </xs:annotation>
              </xs:attribute>
              <xs:attributeGroup ref="SinksAttribute" />
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="EtwProviders">
    <xs:sequence maxOccurs="unbounded">
      <xs:element  name="EtwEventSourceProviderConfiguration" type="EtwEventSourceProviderConfiguration" minOccurs="0" >
        <xs:annotation>
          <xs:documentation>
            ETW collection by event source
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element  name="EtwManifestProviderConfiguration" type="EtwManifestProviderConfiguration" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            ETW collection by manifest
          </xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
    <xs:attributeGroup ref="SinksAttribute" />
  </xs:complexType>

  <xs:complexType name="CrashDumpConfiguration">
    <xs:attribute name="processName" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>
          The name of the process to to monitor for crashes.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attributeGroup ref="SinksAttribute" />
  </xs:complexType>

  <xs:complexType name="CrashDumps">
    <xs:complexContent>
      <xs:extension base="CrashDumpsBase">
        <xs:sequence maxOccurs="unbounded">
          <xs:element name="CrashDumpConfiguration" type="CrashDumpConfiguration">
            <xs:annotation>
              <xs:documentation>
                The crashdump to collect
              </xs:documentation>
            </xs:annotation>
          </xs:element>
        </xs:sequence>
        <xs:attributeGroup ref="SinksAttribute" />
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="DiagnosticInfrastructureLogs">
    <xs:complexContent>
      <xs:extension base="LogsBaseWithSinks">
        <xs:attributeGroup ref="LogLevel" />
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>


  <xs:complexType name="DirectoryBase" />

  <xs:complexType name="DirectoryAbsolute">
    <xs:complexContent>
      <xs:extension base="DirectoryBase">
        <xs:attribute name="path" type="AbsolutePathWithEnvironmentExpansion" use="required">
          <xs:annotation>
            <xs:documentation>
              The absolute path to the directory to monitor.
            </xs:documentation>
          </xs:annotation>
        </xs:attribute>
        <xs:attribute name="expandEnvironment" type="xs:boolean" use="required">
          <xs:annotation>
            <xs:documentation>
              If true, then environment variables in the path will be expanded.
            </xs:documentation>
          </xs:annotation>
        </xs:attribute>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="DirectoryLocalResource">
    <xs:complexContent>
      <xs:extension base="DirectoryBase">
        <xs:attribute name="relativePath" type="RelativePathWithEnvironmentExpansion" use="required">
          <xs:annotation>
            <xs:documentation>
              The path relative to the local resource to monitor.
            </xs:documentation>
          </xs:annotation>
        </xs:attribute>
        <xs:attribute name="name" type="NamedElementNameString" use="required">
          <xs:annotation>
            <xs:documentation>
              The local resource that contains the directory to monitor.
            </xs:documentation>
          </xs:annotation>
        </xs:attribute>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="DirectoryConfiguration">
    <xs:choice>
      <xs:element name="Absolute" type="DirectoryAbsolute">
        <xs:annotation>
          <xs:documentation>
            The absolute path to the directory to monitor.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="LocalResource" type="DirectoryLocalResource">
        <xs:annotation>
          <xs:documentation>
            The path relative to a local resource to monitor.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:choice>
    <xs:attributeGroup ref="DirectoryAttributes" />
  </xs:complexType>

  <xs:complexType name="SpecialLogDirectory">
    <xs:attributeGroup ref="DirectoryAttributes" />
  </xs:complexType>

  <xs:complexType name="DataSources">
    <xs:sequence>
      <xs:element name="DirectoryConfiguration" type="DirectoryConfiguration" maxOccurs="unbounded">
        <xs:annotation>
          <xs:documentation>
            The directory of log files to monitor.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="Directories">
    <xs:complexContent>
      <xs:extension base="LogsBase">
        <xs:all>
          <xs:element name="IISLogs" type="SpecialLogDirectory" minOccurs="0">
            <xs:annotation>
              <xs:documentation>
                The IIS log directory.
              </xs:documentation>
            </xs:annotation>
          </xs:element>
          <xs:element name="FailedRequestLogs" type="SpecialLogDirectory" minOccurs="0">
            <xs:annotation>
              <xs:documentation>
                The failed request log directory.
              </xs:documentation>
            </xs:annotation>
          </xs:element>
          <xs:element name="DataSources" type="DataSources" minOccurs="0">
            <xs:annotation>
              <xs:documentation>
                Additional log directories.
              </xs:documentation>
            </xs:annotation>
          </xs:element>
        </xs:all>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="annotation">
    <xs:attribute name="displayName" type="displayName" use="required">
      <xs:annotation>
        <xs:documentation>
          The display name for the performance counter.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="locale" type="locale" use="optional" default="en-US">
      <xs:annotation>
        <xs:documentation>
          The locale for the performance counter display name.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="PerformanceCounterConfiguration">
    <xs:sequence minOccurs="0">
      <xs:element maxOccurs="unbounded" name="annotation" type="annotation">
        <xs:annotation>
          <xs:documentation>
            The display name and locale for the performance counter
          </xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="counterSpecifier" type="PerformanceCounterPath" use="required">
      <xs:annotation>
        <xs:documentation>
          The path to the performance counter to collect.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="sampleRate" type="PositiveDuration" use="required">
      <xs:annotation>
        <xs:documentation>
          The rate at which the performance counter should be sampled.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="unit" type="xs:string" use="optional">
      <xs:annotation>
        <xs:documentation>
          The unit for the performance counter for display purposes.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attributeGroup ref="SinksAttribute" />
  </xs:complexType>


  <xs:complexType name="PerformanceCounters">
    <xs:complexContent>
      <xs:extension base="LogsBaseWithSinks">
        <xs:sequence maxOccurs="unbounded">
          <xs:element name="PerformanceCounterConfiguration" type="PerformanceCounterConfiguration">
            <xs:annotation>
              <xs:documentation>
                The performance counter to collect.
              </xs:documentation>
            </xs:annotation>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="DockerSources">
    <xs:sequence>
      <xs:element name="Stats" type="DockerStats" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            The docker sources to collect.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
    <xs:attributeGroup ref="SinksAttribute" />
  </xs:complexType>

  <xs:complexType name="DockerStats">
    <xs:complexContent>
      <xs:extension base="LogsBaseWithSinks">
        <xs:attribute name="enabled" type="xs:boolean" use="required">
          <xs:annotation>
            <xs:documentation>
              The path to the performance counter to collect.
            </xs:documentation>
          </xs:annotation>
        </xs:attribute>
        <xs:attribute name="sampleRate" type="PositiveDuration" use="required">
          <xs:annotation>
            <xs:documentation>
              The rate at which the performance counter should be sampled.
            </xs:documentation>
          </xs:annotation>
        </xs:attribute>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="DataSource">
    <xs:attribute name="name" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>
          An XPath expression specifying the logs to collect.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attributeGroup ref="SinksAttribute" />
  </xs:complexType>

  <xs:complexType name="WindowsEventLog">
    <xs:complexContent>
      <xs:extension base="LogsBaseWithSinks">
        <xs:sequence maxOccurs="unbounded">
          <xs:element name="DataSource" type="DataSource">
            <xs:annotation>
              <xs:documentation>
                The event log to monitor.
              </xs:documentation>
            </xs:annotation>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name ="MetricAggregation">
    <xs:attribute name="scheduledTransferPeriod" type="PositiveDuration" use="required" />
  </xs:complexType>

  <xs:complexType name="Metrics">
    <xs:sequence>
      <xs:element name="MetricAggregation" type="MetricAggregation" minOccurs="0" maxOccurs="5" />
    </xs:sequence>
    <xs:attribute name="resourceId" type="xs:string" use="required" />
  </xs:complexType>

  <xs:complexType name="LogsProvider">
    <xs:attribute name="guid" type="guidType" use="required">
      <xs:annotation>
        <xs:documentation>
          The provider's GUID
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="Logs">
    <xs:complexContent>
      <xs:extension base="LogsBaseWithSinks">
        <xs:sequence>
          <xs:element name="Provider" type="LogsProvider" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
        <xs:attributeGroup ref="LogLevel" />
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  <xs:simpleType name="EventVolumeClass">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Small" />
      <xs:enumeration value="Medium" />
      <xs:enumeration value="Large" />
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="DiagnosticMonitorConfiguration">
    <xs:all>
      <xs:element name="Metrics" type="Metrics" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            Should be used by the portal only. Creates 2 new counters tables.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="DiagnosticInfrastructureLogs" type="DiagnosticInfrastructureLogs" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            Configures the logs generated by the underlying diagnostics infrastructure. The diagnostic infrastructure logs are useful for troubleshooting the diagnostics system itself.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="Directories" type="Directories" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            Describes the configuration of a directory to which file-based logs are written.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="PerformanceCounters" type="PerformanceCounters" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            Configures performance counter collection.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="DockerSources" type="DockerSources" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            Configures collection based on apps being run on docker containers.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="WindowsEventLog" type="WindowsEventLog" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            Configures Windows event log collection.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="EtwProviders" type="EtwProviders" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            Configures ETW event collection.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="CrashDumps" type="CrashDumps" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            Configures crashdump collection.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="Logs" type="Logs" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            Configures generic diagnostics event trace listener.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:all>

    <xs:attribute name="overallQuotaInMB" type="xs:unsignedInt" use="optional" default="5120">
      <xs:annotation>
        <xs:documentation>
          The total amount of file system storage allocated for all logging buffers.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="useProxyServer" type="xs:boolean" use="optional" default="true">
      <xs:annotation>
        <xs:documentation>
          Force the Monitoring Agent to use the specified IE proxy server if specified.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="eventVolume" type="EventVolumeClass" use="optional">
      <xs:annotation>
        <xs:documentation>
          Specifies the expected log volume.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attributeGroup ref="SinksAttribute"/>
  </xs:complexType>

  <xs:complexType name="SinkChannel">
    <xs:attribute name="name" type="sinkName" use="required" />
    <xs:attribute name="logLevel" type="LogLevel" use="required" />
  </xs:complexType>

  <xs:complexType name="SinkChannels">
    <xs:sequence maxOccurs="unbounded">
      <xs:element name="Channel" minOccurs="1" type="SinkChannel" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="ApplicationInsightsSink">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="telemetryEndPoint" use="optional" type="xs:string" />
        <xs:attribute name="enableStatusMonitor" use="optional" type="xs:boolean" default="true" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:complexType name="ApplicationInsightsProfilerSink">
    <xs:simpleContent>
      <xs:extension base="xs:string" />
    </xs:simpleContent>
  </xs:complexType>

  <xs:complexType name="EventHubSink">
    <xs:attribute name="Url" type="xs:anyURI" use="required" />
    <xs:attribute name="SharedAccessKeyName" type="xs:string" use="required" />
  </xs:complexType>

  <xs:complexType name="StorageAccountSink">
    <xs:attribute name="name" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>
          The name of storage account to store the diagnostics data
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="endpoint" type="xs:anyURI" use="optional" default="https://core.windows.net" >
      <xs:annotation>
        <xs:documentation>
          The storage endpoint
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="Sink">
    <xs:sequence>
      <xs:choice>
        <xs:element name="ApplicationInsights" type="ApplicationInsightsSink" />
        <xs:element name="ApplicationInsightsProfiler" type="ApplicationInsightsProfilerSink" />
        <xs:element name="EventHub" type="EventHubSink" />
        <xs:element name="StorageAccount" type="StorageAccountSink" />
      </xs:choice>
      <xs:element name="Channels" minOccurs="0" maxOccurs="1" type="SinkChannels" />
    </xs:sequence>
    <xs:attribute name="name" type="sinkName" use="required" />
  </xs:complexType>

  <xs:simpleType name="StorageType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="TableAndBlob" />
      <xs:enumeration value="Table" />
      <xs:enumeration value="Blob" />
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="StorageAccount">
    <xs:attribute name="name" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>
          The name of storage account to store the diagnostics data
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="key" type="xs:string" use="optional" default="">
      <xs:annotation>
        <xs:documentation>
          Actual storage account key
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>

    <xs:attribute name="endpoint" type="xs:anyURI" use="optional" default="https://core.windows.net" >
      <xs:annotation>
        <xs:documentation>
          The storage endpoint
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="sasToken" type="xs:string" use="optional" default="">
      <xs:annotation>
        <xs:documentation>
          Shared access signature token
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="EventHub">
    <xs:attribute name="Url" type="xs:anyURI" use="required" />
    <xs:attribute name="SharedAccessKeyName" type="xs:string" use="required" />
    <xs:attribute name="SharedAccessKey" type="xs:string" use="required" />
  </xs:complexType>

  <xs:complexType name="SecondaryStorageAccounts">
    <xs:sequence maxOccurs="unbounded">
      <xs:element name="StorageAccount" minOccurs="0" type="StorageAccount"></xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="SecondaryEventHubs">
    <xs:sequence maxOccurs="unbounded">
      <xs:element name="EventHub" minOccurs="0" type="EventHub"></xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="PublicConfig">
    <xs:all>
      <xs:element name="WadCfg">
        <xs:complexType>
          <xs:all>
            <xs:element name="DiagnosticMonitorConfiguration" type="DiagnosticMonitorConfiguration" minOccurs="1" maxOccurs="1" />
            <xs:element name="SinksConfig" minOccurs="0" maxOccurs="1">
              <xs:complexType>
                <xs:sequence maxOccurs="unbounded">
                  <xs:element name="Sink" type="Sink" minOccurs="1" />
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:all>
        </xs:complexType>
      </xs:element>
      <xs:element name="LocalResourceDirectory" minOccurs="0" maxOccurs="1"  type="DirectoryAbsolute" />
      <xs:element name="StorageAccount" minOccurs="0" maxOccurs="1" type="xs:string" />
      <xs:element name="StorageType" minOccurs="0" maxOccurs="1" type="StorageType" default="Table"/>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="PrivateConfig">
    <xs:all>
      <xs:element name="StorageAccount" minOccurs="1" type="StorageAccount"/>
      <xs:element name="EventHub" minOccurs="0" type="EventHub" />
      <xs:element name="SecondaryStorageAccounts" minOccurs="0" type="SecondaryStorageAccounts" />
      <xs:element name="SecondaryEventHubs" minOccurs="0" type="SecondaryEventHubs" />
    </xs:all>
  </xs:complexType>

  <xs:element name="DiagnosticsConfiguration">
    <xs:complexType>
      <xs:all>
        <xs:element name="PublicConfig" type="PublicConfig" minOccurs="1" maxOccurs="1" />
        <xs:element name="PrivateConfig" type="PrivateConfig" minOccurs="1" maxOccurs="1" />
        <xs:element name="IsEnabled" type="xs:boolean" minOccurs="1" maxOccurs="1" />
      </xs:all>
    </xs:complexType>
  </xs:element>

</xs:schema>