捕获日志并将其制成文本文件

问题描述 投票:0回答:1

[在下面的条件下,Logger()捕获了将用作日志的适当文本,我希望将这些日志制作为文本文件。


try{
      if (mailRecipient.Resolved)
      {
        mail.Send();
        Logger("Email send to : " + recipients);
      }
      else
      {
        Logger("There is no such record in your address book.");
      }
    }
    catch (System.Exception ex)
    {
      Logger("An exception is occured in the code of add-in.");
      Logger(ex.Message);
      Logger("Stack Trace :" + ex.StackTrace);
    }

拥有文本文件之后,我将不得不从其路径中获取文本文件并将其添加为以下功能的附件。


logFile = //path of the text file;

mail.Attachments.Add(logFile);

我如何捕获这些日志并将其制成文本文件,然后将该文本文件用作附件?

c# string methods parameter-passing text-files
1个回答
1
投票

https://docs.microsoft.com/en-us/dotnet/api/system.io.file.writealltext?view=netcore-3.1

您可以使用此功能在特定位置创建文本文件并向其中写入所需的数据。

一旦用必要的数据编写了文本文件,您只需引用文件的路径以作为附件发送。

© www.soinside.com 2019 - 2024. All rights reserved.