我正在尝试将日志文件附加到电子邮件中。
我的代码是:
**<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被另一个进程使用。
为什么我收到此错误?
答案 0 :(得分: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}" />
答案 1 :(得分:0)
在尝试通过电子邮件发送之前,请确保该文件已关闭。