
로깅은 디버깅뿐만 아니라 애플리케이션에 대한 작업 정보를 수집하고 분석하는 데 사용됩니다. 이 정보는 로그라는 파일에 기록됩니다. 로그 파일은 클라이언트 애플리케이션의 작동에 대한 시스템 정보를 포함하며, 예를 들어 사용자 또는 프로그램의 작업을 포함합니다.
이 기사에서는 C# .NET를 사용하여 EWS 클라이언트 활동 로깅을 설정하는 방법을 다룰 것입니다.
- MS Exchange Web Services와 작업하기 위한 C# .NET API
- App.config 파일을 사용하여 활동 로깅 활성화
- appsettings.json 파일을 사용하여 활동 로깅 활성화
- 프로그램 코드에서 활동 로깅 활성화
- 로그 파일 정보의 예
MS Exchange Web Services와 작업하기 위한 C# .NET API
MS Exchange Web Services를 관리하기 위해 Aspose.Email for .NET을 사용할 것입니다.
이 API는 MS Exchange Server의 다양한 서비스에 원활하게 접근할 수 있도록 해주는 강력한 API입니다. 또한 이메일 클라이언트 애플리케이션을 구현하기 위한 많은 기능을 제공합니다.
API의 DLL을 다운로드하거나 다음 명령을 사용하여 NuGet에서 설치할 수 있습니다.
PM> Install-Package Aspose.Email
App.config 파일을 사용하여 활동 로깅 활성화
이 옵션은 app.config
가 애플리케이션 구성 파일을 유지하는 선호 방법인 애플리케이션에 적합합니다.
다음은 C#에서 EWSClient의 로깅을 활성화하는 단계입니다.
- 먼저, C# 프로젝트에 애플리케이션 구성 파일을 추가합니다. 이전에 추가되지 않았다면 추가합니다.
- 그런 다음, 구성 파일에 다음 내용을 추가합니다.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Aspose.Email.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<Aspose.Email.Properties.Settings>
<setting name="EWSDiagnosticLog" serializeAs="String">
<value>..\..\..\Log\Aspose.Email.EWS.log</value>
</setting>
<setting name="EWSDiagnosticLog_UseDate" serializeAs="String">
<value>False</value>
</setting>
</Aspose.Email.Properties.Settings>
</applicationSettings>
</configuration>
두 개의 설정 섹션을 볼 수 있습니다:
EWSDiagnosticLog
- 로그 파일에 대한 상대 경로 또는 절대 경로를 지정합니다.EWSDiagnosticLog_UseDate
- 로그 파일 이름에 현재 날짜의 문자열 표현을 추가할지 여부를 지정합니다.
appsettings.json 파일을 사용하여 활동 로깅 활성화
이 옵션은 .NET Core 애플리케이션에 선호됩니다.
다음은 C#에서 EWSClient의 로깅을 활성화하는 단계입니다.
- 먼저, C# 프로젝트에
appsettings.json
구성 파일을 추가합니다. 이전에 추가되지 않았다면 추가합니다. 프로젝트 파일의 ItemGroup 섹션에 다음 줄이 포함되어 있는지 확인합니다:
<Content Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
- 그런 다음, appsettings.json 파일에 다음 내용을 추가합니다.
{
"EWSDiagnosticLog": "ews.log",
"EWSDiagnosticLog_UseDate": true
}
두 개의 속성을 볼 수 있습니다:
EWSDiagnosticLog
- 로그 파일에 대한 상대 경로 또는 절대 경로를 지정합니다.EWSDiagnosticLog_UseDate
- 로그 파일 이름에 현재 날짜의 문자열 표현을 추가할지 여부를 지정합니다.
프로그램 코드에서 활동 로깅 활성화
코드에서 즉시 로깅을 활성화할 수도 있습니다. 주의: 구성 파일을 사용하여 이미 로깅을 활성화한 경우에도 이 옵션이 적용됩니다.
다음은 C#에서 EWSClient의 로깅을 활성화하는 단계입니다.
- 먼저, EWSClient를 생성합니다.
- 둘째, LogFileName 속성을 사용하여 로그 파일의 경로를 설정합니다.
- 마지막으로, 필요하다면 UseDateInLogFileName 속성을 설정합니다.
using (var client = EWSClient.GetEWSClient("https://outlook.office365.com/EWS/Exchange.asmx", credentials))
{
client.LogFileName = @"Aspose.Email.EWS.log";
client.UseDateInLogFileName = false;
}
로그 파일 정보의 예
아래는 ListMessages 메서드가 실행될 때 로그 파일 항목의 예입니다. 각 새로운 항목은 타임스탬프에 의해 선행됩니다.
로그 파일에서 다음 항목을 구분할 수 있습니다:
- 로그 파일 헤더. Aspose.Email 버전, 이름 및 시작 시간을 포함합니다.
Aspose.Email for .NET [22.10.0.0] EWS Client diagnostic log
Started: 07.11.2022 13:40:16
- 서버에 대한 SOAP 요청.
07.11.2022 13:40:16 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ExchangeImpersonation xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
<ConnectingSID>
<SmtpAddress>someaddress@someorg.onmicrosoft.com</SmtpAddress>
</ConnectingSID>
</ExchangeImpersonation>
<RequestServerVersion xmlns="http://schemas.microsoft.com/exchange/services/2006/types" Version="Exchange2013" />
</soap:Header>
<soap:Body>
<FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" Traversal="Shallow">
<ItemShape>
<BaseShape xmlns="http://schemas.microsoft.com/exchange/services/2006/types">IdOnly</BaseShape>
</ItemShape>
<IndexedPageItemView MaxEntriesReturned="2147483647" Offset="0" BasePoint="Beginning" />
<ParentFolderIds>
<DistinguishedFolderId xmlns="http://schemas.microsoft.com/exchange/services/2006/types" Id="inbox" />
</ParentFolderIds>
</FindItem>
</soap:Body>
</soap:Envelope>
- HTTP 응답 헤더
07.11.2022 13:40:18 Cache-Control: private
Transfer-Encoding: chunked
Server: Microsoft-IIS/10.0
request-id: 5c777b61-e3d9-c262-fbb0-6f071d9ff68a
Alt-Svc: h3=":443", h3-29=":443"
X-CalculatedFETarget: CH0PR03CU015.internal.outlook.com, BL0PR02CU002.internal.outlook.com
X-BackEndHttpStatus: 200, 200, 200
Set-Cookie: exchangecookie=bf07039c0ee942438170c2958ca2d330; expires=Tue, 07-Nov-2023 10:40:17 GMT; path=/; secure; HttpOnly
X-CalculatedBETarget: BLAPR10MB4915.namprd10.PROD.OUTLOOK.COM
X-RUM-Validated: 1
x-ms-appId: 3fe84e63-c57b-48eb-ab41-879415751cfd
Restrict-Access-Confirm: 1
x-EwsHandler: FindItem
X-AspNet-Version: 4.0.30319
X-BeSku: WCS6
X-DiagInfo: BLAPR10MB4915
X-BEServer: BLAPR10MB4915
X-Proxy-RoutingCorrectness: 1
X-Proxy-BackendServerStatus: 200
X-FEProxyInfo: AS9PR06CA0693.EURPRD06.PROD.OUTLOOK.COM
X-FEEFZInfo: DHR
X-FEServer: BL0PR02CA0063, CH0PR03CA0449, AS9PR06CA0693
X-FirstHopCafeEFZ: DHR
X-Powered-By: ASP.NET
Date: Mon, 07 Nov 2022 10:40:17 GMT
Content-Type: text/xml; charset=utf-8
- SOAP 서버 응답.
07.11.2022 13:40:18 <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ExchangeImpersonation xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
<ConnectingSID>
<SmtpAddress>someaddress@someorg.onmicrosoft.com</SmtpAddress>
</ConnectingSID>
</ExchangeImpersonation>
<RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" />
</soap:Header>
<soap:Body>
<GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<ItemShape>
<BaseShape xmlns="http://schemas.microsoft.com/exchange/services/2006/types">IdOnly</BaseShape>
<AdditionalProperties xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
<FieldURI FieldURI="item:Attachments" /><FieldURI FieldURI="item:DateTimeCreated" />
<FieldURI FieldURI="item:DateTimeReceived" /><FieldURI FieldURI="item:DateTimeSent" />
<FieldURI FieldURI="item:IsDraft" /><FieldURI FieldURI="item:IsFromMe" />
<FieldURI FieldURI="item:HasAttachments" /><FieldURI FieldURI="item:IsUnmodified" />
<FieldURI FieldURI="item:ItemClass" /><FieldURI FieldURI="item:IsSubmitted" />
<FieldURI FieldURI="item:IsResend" /><FieldURI FieldURI="item:DisplayCc" /><FieldURI FieldURI="item:DisplayTo" />
<FieldURI FieldURI="item:Attachments" /><FieldURI FieldURI="item:LastModifiedTime" />
<FieldURI FieldURI="item:Size" /><FieldURI FieldURI="item:Subject" />
<FieldURI FieldURI="item:InternetMessageHeaders" /><FieldURI FieldURI="message:IsRead" />
<FieldURI FieldURI="message:InternetMessageId" /><FieldURI FieldURI="message:Sender" />
<FieldURI FieldURI="message:CcRecipients" /><FieldURI FieldURI="message:ToRecipients" />
<FieldURI FieldURI="message:BccRecipients" /><FieldURI FieldURI="message:From" />
</AdditionalProperties>
</ItemShape>
<ItemIds>
<ItemId
Id="AAMkAGJhZjYzY2I5LTdjYWMtNGFmMC05ODI1LTA5MTAzYTgwZTc4OQBGAAAAAABdN1MC60QcSpWwPYUTPhL2BwATlR+p0q0wT6WD0+d4WJhWAAAAAAEMAAATlR+p0q0wT6WD0+d4WJhWAACp2kv8AAA="
xmlns="http://schemas.microsoft.com/exchange/services/2006/types" />
</ItemIds>
</GetItem>
</soap:Body>
</soap:Envelope>
무료 API 라이센스 받기
제한 없이 Aspose.Email for .NET을 사용할 수 있는 무료 임시 라이센스을 받을 수 있습니다.
결론
이 기사에서는 C#을 사용하여 EWS 클라이언트에서 활동 로깅을 설정하는 방법을 배웠습니다. 이 기능은 클라이언트 애플리케이션을 더 잘 모니터링할 수 있게 해줍니다. 또한 문서를 탐색하여 Aspose.Email for .NET에 대해 자세히 읽고 질문은 포럼에 문의할 수 있습니다.