다음을 통해 공유


방법: 상태 모니터링 알림을 위한 전자 메일 보내기

업데이트: 2007년 11월

ASP.NET 상태 모니터링 웹 이벤트가 발생할 경우 전자 메일 알림을 보내도록 ASP.NET 응용 프로그램을 구성할 수 있습니다. 이를 위해 사용 가능한 전자 메일 웹 이벤트 공급자 중 하나를 구성할 수 있습니다.

ASP.NET 상태 모니터링 시스템에는 상태 모니터링 웹 이벤트 데이터를 사용하는 몇 가지 이벤트 공급자가 제공됩니다. 이 중에서 EventLogWebEventProvider, SqlWebEventProviderWmiWebEventProvider 이벤트 공급자만 루트 Web.config 파일에 미리 구성되어 있습니다. 이 항목에서는 전자 메일 웹 이벤트 공급자를 위해 구성 설정을 추가하는 방법과 이러한 공급자가 특정 이벤트를 수신하도록 설정하는 방법에 대해 설명합니다.

공급자가 수신할 수 있는 웹 이벤트 목록을 보려면 루트 Web.config 파일의 <eventMappings> 요소 또는 ASP.NET 상태 모니터링 개요의 "웹 이벤트" 단원을 참조하십시오.

웹 응용 프로그램에서 전자 메일 보내기

이 항목의 코드 예제를 실행하려면 전자 메일 메시지를 보내도록 웹 응용 프로그램을 구성해야 합니다. 다음 절차에서는 웹 서버에 SMTP(Simple Mail Transfer Protocol) 서비스가 이미 설치 및 구성되어 있고 전자 메일 메시지를 보낼 수 있는 SMTP 서버에 액세스할 수 있는 경우에 응용 프로그램을 구성하는 방법을 보여 줍니다. 자세한 내용은 방법: IIS 6.0에서 SMTP 가상 서버 설치 및 구성을 참조하십시오.

전자 메일을 보내도록 ASP.NET 응용 프로그램을 구성하려면

  • 응용 프로그램의 Web.config 파일을 열고 <system.net> 섹션 내에 있는 <mailSettings> 요소를 구성합니다. <smtp> 요소의 deliveryMethod 특성에 전송 방법을 지정하고 <network> 요소의 host 특성에 SMTP 서버의 이름을 지정해야 합니다. 또한 defaultCredentials 특성을 true로 설정하는 것이 좋습니다. 다른 특성도 사용할 수 있으며 이에 대해서는 요소 항목을 참조하십시오.

    구성 설정은 다음 예제와 같습니다.

    <configuration xmlns="https://schemas.microsoft.com/.NetConfiguration/v2.0">
      <system.net>
        <mailSettings>      <smtp deliveryMethod="Network">        <network           defaultCredentials="true"           host="smtpservername"           />      </smtp>    </mailSettings>
      </system.net>
      <!-- Other configuration settings. -->
    </configuration>
    

메일 공급자 구성

SimpleMailWebEventProvider 웹 이벤트 공급자를 구성하려면

  1. 응용 프로그램의 Web.config 파일을 열고 <system.web> 섹션의 <healthMonitoring> 요소 내에 <providers> 요소를 새로 추가합니다. 이 새 providers 요소에서 SimpleMailWebEventProvider 웹 이벤트 공급자를 구성합니다. 이 공급자는 ASP.NET 상태 모니터링 시스템에 포함되어 있지만 루트 Web.config 파일에 미리 구성되어 있지는 않습니다.

    구성 설정은 다음 예제와 같습니다.

    <configuration>
      <system.web>
        <healthMonitoring enabled="true" heartbeatInterval="0">
          <providers>
            <add           name="exampleMailWebEventProvider"           type="System.Web.Management.SimpleMailWebEventProvider"          to="someone@contoso.com"          from="someone@contoso.com"          buffer="false"          subjectPrefix="WebEvent has fired"          />
          </providers>
        </healthMonitoring>
      </system.web>
      <!-- Other configuration settings. -->
    </configuration>
    

    이 절차를 수행할 때 buffer 특성을 false로 설정하여 이벤트 버퍼링을 해제하십시오. name 특성은 임의의 값으로 지정할 수 있으며 다음 단계에서 공급자를 식별하는 데 사용됩니다. to 및 from 특성을 자신의 전자 메일 주소로 변경하여 이 절차의 뒷부분에 나오는 테스트 단계를 완료하십시오.

  2. <healthMonitoring> 요소 내에 <rules> 요소를 새로 추가합니다. 이 새 rules 요소는 모든 웹 이벤트를 수신하도록 전자 메일 공급자를 구성합니다.

    구성 설정은 다음 예제와 같습니다.

    <configuration>
      <system.web>
        <healthMonitoring enabled="true" heartbeatInterval="0">
          <!-- <providers> element from the previous step -->
          <rules>
            <add           name="Testing Mail Event Providers"           eventName="All Events"           provider="exampleMailWebEventProvider"          profile="Default"           minInstances="1"           maxLimit="Infinite"           minInterval="00:01:00"          custom=""           />
          </rules>
        </healthMonitoring>
      </system.web>
      <!-- Other configuration settings. -->
    </configuration>
    

    provider 특성은 이전 단계에서 providers 요소의 name 특성과 같습니다. 이 rules 요소의 eventName 특성은 루트 Web.config 파일에 미리 구성된 eventMappings 요소의 name 특성과 같습니다. 이 구성은 ASP.NET 응용 프로그램에서 발생하는 모든 웹 이벤트에 대해 전자 메일 메시지를 보냅니다. 이러한 이벤트에는 응용 프로그램 시작/중지, 구성 변경 및 요청이 포함되며 이 외에 다른 이벤트도 포함될 수 있습니다.

    이 절차를 수행할 때 rules 요소와 이전 단계에 나온 provider 요소를 같은 구성 파일에 정의합니다. provider 요소는 구성 파일 체인에서 루트 Web.config 파일에 가까이 있는 상위 수준의 구성 파일에 있을 수도 있습니다.

  3. 응용 프로그램에서 페이지를 요청하여 구성을 테스트합니다. 구성 설정을 변경한 경우에는 응용 프로그램 다시 시작 이벤트가 발생하여 전자 메일 메시지를 이미 받았을 수 있습니다. 전송된 전자 메일에는 다음 예제 메시지와 비슷하게 제목 줄과 메시지 본문이 포함되어 있습니다.

    Subject: Event Notification 1, part 1: WebEvent has fired <event>
    Body: 
    

Application Information --------------- Application domain: /LM/w3svc/1/ROOT/ Trust level: Full Application Virtual Path: / Application Path: Machine name:

Events --------------- ---------------

TemplatedMailWebEventProvider 웹 이벤트 공급자를 구성하려면

  1. 응용 프로그램의 Web.config 파일을 열고 <system.web> 섹션의 <healthMonitoring> 요소 내에 <providers> 요소를 새로 추가합니다. 이 새 providers 요소에서 TemplatedMailWebEventProvider 웹 이벤트 공급자를 구성합니다. 이 공급자는 ASP.NET 상태 모니터링 시스템에 포함되어 있지만 루트 Web.config 파일에 미리 구성되어 있지는 않습니다.

    구성 설정은 다음 예제와 같습니다.

    <configuration>
      <system.web>
        <healthMonitoring enabled="true" heartbeatInterval="0">
          <providers>        <add           name="exampleTemplatedMailWebEventProvider"           type="System.Web.Management.TemplatedMailWebEventProvider"          template="template.aspx"           detailedTemplateErrors="true"          to="someone@contoso.com"          from="someone@contoso.com"          buffer="true"          bufferMode="Notification"          maxMessagesPerNotification="1"          maxEventsPerMessage="1"           />      </providers>
        </healthMonitoring>
      </system.web>
      <!-- Other configuration settings. -->
    </configuration>
    

    이 절차를 수행할 때 buffer 특성을 false로 설정하여 이벤트 버퍼링을 설정하십시오. bufferMode 특성 값 Notification은 루트 Web.config 파일에 미리 정의되어 있습니다. 버퍼링에 대한 자세한 내용은 ASP.NET 상태 모니터링 이벤트 확장을 참조하십시오.

    name 특성은 임의의 값으로 지정할 수 있으며 다음 단계에서 공급자를 식별하는 데 사용됩니다. to 및 from 특성을 자신의 전자 메일 주소로 변경하여 이 절차의 뒷부분에 나오는 테스트 단계를 완료하십시오.

  2. <healthMonitoring> 요소 내에 <rules> 요소를 새로 추가합니다. 이 새 rules 요소는 모든 웹 이벤트를 수신하도록 전자 메일 공급자를 구성합니다.

    구성 설정은 다음 예제와 같습니다.

    <configuration>
      <system.web>
        <healthMonitoring enabled="true" heartbeatInterval="0">
          <!-- <providers> element from the previous step -->
          <rules>
            <add           name="Testing Templated Mail Event Providers"           eventName="Request Processing Events"           provider="exampleTemplatedMailWebEventProvider"          profile="Default"           minInstances="1"           maxLimit="Infinite"           minInterval="00:00:00"          custom=""           />
          </rules>
        </healthMonitoring>
      </system.web>
      <!-- Other configuration settings. -->
    </configuration>
    

    provider 특성은 이전 단계에서 providers 요소의 name 특성과 같습니다. 이 rules 특성의 eventName 특성은 루트 Web.config 파일에 미리 구성된 eventMappings 요소의 name 특성과 같습니다. 이 구성은 ASP.NET 응용 프로그램에서 페이지 또는 다른 리소스를 요청할 때마다 전자 메일 메시지를 보냅니다.

  3. Template.aspx라는 전자 메일 템플릿 파일을 만들어 응용 프로그램의 루트에 넣습니다. 이 파일 이름은 providers 요소의 template 특성에 대한 값입니다. 응용 프로그램에서 요청 이벤트가 발생하면 문자열 식을 사용하여 템플릿 파일에 데이터를 채운 다음 이 파일을 알림 전자 메일 메시지로 전송합니다. 식을 사용하는 방법에 대한 내용은 ASP.NET 식 개요를 참조하십시오.

    템플릿 파일은 다음 예제와 같습니다.

    <%@ Page Language="cs" %>
    <%@ Import Namespace="System.Web.Management" %>
    
    <script >
    
    void Page_Load() 
    {
        MailEventNotificationInfo info = TemplatedMailWebEventProvider.CurrentNotification;
        Label0.Text = "EventsDiscardedByBuffer: " + info.EventsDiscardedByBuffer + '\n';
        Label1.Text = "EventsInBuffer: " + info.EventsInBuffer + '\n';
        Label2.Text = "NotificationSequence: " + info.NotificationSequence + '\n';
        Label3.Text = "NotificationType: " + info.NotificationType + '\n';
        Label4.Text = "EventsInNotification: " + info.EventsInNotification + '\n';
        Label5.Text = "EventsRemaining: " + info.EventsRemaining + '\n';
        Label6.Text = "MessagesInNotification: " + info.MessagesInNotification + '\n';
        Label7.Text = "eventsDiscardedDueToMessageLimit: " + info.EventsDiscardedDueToMessageLimit + '\n';
        Label8.Text = "messageSequence: " + info.MessageSequence + '\n';
        Label9.Text = "LastNotificationUtc: " + info.LastNotificationUtc.ToLocalTime().ToString() + '\n';
    
        EventList.DataSource = info.Events;
        EventList.DataBind();
    }
    </script>
    
    <asp:Label  id="Label0" /><p />
    <asp:Label  id="Label1" /><p />
    <asp:Label  id="Label2" /><p />
    <asp:Label  id="Label3" /><p />
    <asp:Label  id="Label4" /><p />
    <asp:Label  id="Label5" /><p />
    <asp:Label  id="Label6" /><p />
    <asp:Label  id="Label7" /><p />
    <asp:Label  id="Label8" /><p />
    <asp:Label  id="Label9" /><p />
    
    <asp:DataList id="EventList" >
        <ItemTemplate>
          Event Received 
          Sequence: <%# DataBinder.Eval(Container.DataItem, "EventSequence") %><br>
          Details: <%# Container.DataItem.ToString() %>
        </ItemTemplate>
    </asp:DataList>
    
  4. 응용 프로그램에서 페이지를 요청하여 구성을 테스트합니다. 그러면 다음 예제 메시지와 비슷한 제목 줄과 메시지 본문이 포함된 전자 메일 메시지가 신속하게 전달됩니다.

    Subject: Event Notification 1, part 1: <event>
    Body: 
    EventsDiscardedByBuffer: 0 
    EventsInBuffer: 0 
    NotificationSequence: 1 
    NotificationType: Flush 
    EventsInNotification: 1 
    EventsRemaining: 0 
    MessagesInNotification: 1 
    eventsDiscardedDueToMessageLimit: 0 
    messageSequence: 1 
    LastNotificationUtc: 1/1/0001 12:00:00 AM 
    Event Received Sequence: 1
    Details: 
    <event information>
    

참고 항목

참조

healthMonitoring 요소(ASP.NET 설정 스키마)

healthMonitoring에 대한 eventMappings 요소(ASP.NET 설정 스키마)

healthMonitoring에 대한 providers 요소(ASP.NET 설정 스키마)

healthMonitoring에 대한 rules 요소(ASP.NET 설정 스키마)

<smtp> 요소(네트워크 설정)

기타 리소스

ASP.NET 상태 모니터링 개요

ASP.NET 상태 모니터링 이벤트 버퍼링

ASP.NET 상태 모니터링 구성