翻譯|使用教程|編輯:胡濤|2023-03-22 13:06:49.750|閱讀 180 次
概述:在本文中,我們將介紹如何使用 C# .NET 設(shè)置 EWS 客戶端活動(dòng)日志記錄。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Aspose API支持流行文件格式處理,并允許將各類文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
Aspose.Email 是用于輕松的開發(fā) email 功能的應(yīng)用程序的一組控件,基于 ASP.NET 的Web應(yīng)用、Web服務(wù)和Windows 應(yīng)用。支持 Outlook PST, EML, MSG, and MHT 格式. 允許開發(fā)者直接與 SMTP, POP, FTP, 和 MS Exchange 服務(wù)器進(jìn)行工作。支持郵件合并、行事歷、定制郵件標(biāo)題和內(nèi)容、嵌入文件等
日志記錄用于調(diào)試,以及收集和分析有關(guān)應(yīng)用程序的工作信息。此信息被寫入稱為日志的文件。日志文件包含有關(guān)客戶端應(yīng)用程序操作的系統(tǒng)信息,例如,用戶或程序操作。
在本文中,我們將介紹如何使用 C# .NET 設(shè)置 EWS 客戶端活動(dòng)日志記錄。
為了管理 MS Exchange Web 服務(wù),我們將使用Aspose.Email for .NET。
它是一個(gè)強(qiáng)大的 API,允許無縫訪問 MS Exchange Server 的各種服務(wù)。此外,它還提供了許多功能來實(shí)現(xiàn)電子郵件客戶端應(yīng)用程序。
您可以下載API 的 DLL 或使用以下命令從NuGet安裝它。
PM> Install-Package Aspose.Email
此選項(xiàng)適用于app.config保留應(yīng)用程序配置的首選方式的應(yīng)用程序。
以下是在 C# 中啟用EWSClient 日志記錄的步驟。
<?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>
我們可以看到兩個(gè)設(shè)置部分:
此選項(xiàng)是 .NET Core 應(yīng)用程序的首選。
以下是在 C# 中啟用EWSClient 日志記錄的步驟。
<Content Include="appsettings.json"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content>
{ "EWSDiagnosticLog": "ews.log", "EWSDiagnosticLog_UseDate": true }
我們可以看到兩個(gè)屬性:
您還可以在代碼中立即啟用日志記錄。注意:即使您已經(jīng)使用配置文件啟用了日志記錄,也會(huì)應(yīng)用此選項(xiàng)。
以下是在 C# 中啟用EWSClient 日志記錄的步驟。
using (var client = EWSClient.GetEWSClient("http://outlook.office365.com/EWS/Exchange.asmx", credentials)) { client.LogFileName = @"Aspose.Email.EWS.log"; client.UseDateInLogFileName = false; }
下面是執(zhí)行ListMessages方法時(shí)日志文件條目的示例。每個(gè)新條目之前都有一個(gè)時(shí)間戳。
可以在日志文件中區(qū)分以下條目:
Aspose.Email for .NET [22.10.0.0] EWS Client diagnostic log Started: 07.11.2022 13:40:16
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>
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
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>
在本文中,你學(xué)習(xí)了使用 C# .NET 在 EWS 客戶端中設(shè)置活動(dòng)日志記錄。如您還有其他相關(guān)問題,歡迎咨詢我們獲取幫助或加入我們官方交流群。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn