0

我正在尝试将日志文件附加到电子邮件。

我的代码是:

**<loadtasks assembly=".../tasks.dll" />
<record name="c:foo\log.txt" action="Start" />
<target name="email">
<mail
      from="abc@foo.com"
      tolist="xyz@foo.com"
      subject="Build"
      message="Build Failed"
      mailhost="smtp.anywhere.net">
      <files>
        <include name="c:foo\log.txt" />
      </files>
      <attachment>
        <include name="c:foo\log.txt" />
      </attachment>
    </mail>
</target>
<record name="c:foo\log.txt" action="Close" />**

我的命令是:

nant -f:filename.build email -l:c:foo\log.txt

我收到以下错误:

System.Security.SecurityException: Request for the permission of type 'System.Se
curity.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral,
 PublicKeyToken=b77a5c561934e089' failed.
   at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMa
rk& stackMark, Boolean isPermSet)
   at System.Security.CodeAccessPermission.Demand()
   at System.IO.FileSystemInfo.get_FullName()
   at NAnt.Contrib.Tasks.RecordTask.ExecuteTask()
   at NAnt.Core.Task.Execute()
   at NAnt.Core.Project.InitializeProjectDocument(XmlDocument doc)
   at NAnt.Core.Project.Execute()
   at NAnt.Core.Project.Run()

当我不使用<record>任务时,它会出现另一个错误,例如无法附加 txt 文件。bcoz 它被另一个进程使用。

为什么我会收到此错误?

4

2 回答 2

0

在尝试通过电子邮件发送文件之前,请确保文件已关闭。

于 2013-03-29T23:15:05.657 回答
0

我做了类似刷新记录任务的事情,就在发送电子邮件之前,然后将文件复制到电子邮件中,希望这个解决方法有效

    <echo>${emailsubject}</echo>    
    <echo>Sending Email</echo>
    <echo>Attaching File : ${build.log.dir}/email_${build.log.filename}</echo>
    <echo>Attaching File : ${path.vsshelper.log}/logs/email_${build.log.getlistoffiles}</echo>

    <record name="${build.log.dir}/${build.log.filename}"       action="Flush" level="Verbose"/>
    <sleep milliseconds="5000" />
    <copy file= "${build.log.dir}/${build.log.filename}" tofile="${build.log.dir}/email_${build.log.filename}" />   
    <copy file= "${path.vsshelper.log}/logs/${build.log.getlistoffiles}" tofile="${path.vsshelper.log}/logs/email_${build.log.getlistoffiles}" />           
于 2013-03-28T03:36:24.797 回答