Nat*_*son 9 azure-web-sites azure-webjobs azure-webjobssdk
我正在使用带有Windows Azure Storage SDK的Webjob.当一个新项目出现在队列中时,我的类中会调用一个方法.根据SDK文档,如果我将TextWriter作为参数添加到我的方法中,SDK将为我提供一个我可以写入的TextWriter,它将显示在Webjob的日志记录基础结构中.这使得诊断问题和解决问题非常容易.
public async static void ProcessQueueMessage([QueueTrigger("queueName")]MyModelType model, TextWriter logger)
{
await logger.WriteLineAsync(string.Format("Processing Item {0}", model.SasUrl));
// Some work here
await logger.WriteLineAsync(string.Format("Done Processing Item {0}", model.SasUrl));
}
Run Code Online (Sandbox Code Playgroud)
但是,很常见的是,在我的方法体内,TextWriter正在被处理掉.我在第二个logger.WriteLineAsync上遇到以下异常:
System.ObjectDisposedException was unhandled by user code
HResult=-2146232798
Message=Cannot write to a closed TextWriter.
Source=mscorlib
ObjectName=""
StackTrace:
at System.IO.__Error.WriterClosed()
at System.IO.StringWriter.Write(Char[] buffer, Int32 index, Int32 count)
at System.IO.TextWriter.WriteLine(String value)
at System.IO.TextWriter.SyncTextWriter.WriteLine(String value)
at System.IO.TextWriter.SyncTextWriter.WriteLineAsync(String value)
at NameOfProject.Program.<ProcessQueueMessage>d__8.MoveNext() in c:\Dev\Path\To\Program.cs:line 173
InnerException:
Run Code Online (Sandbox Code Playgroud)
我找不到其他人遇到这个问题,所以我无法想象SDK或webjobs基础设施中存在错误.
有没有办法告诉记录器是否在通话前被处理掉了?
有没有办法在我的方法中创建一个新的记录器,它将参与WebJobs记录子系统和UI?
Vic*_*aci 30
那是因为你的方法返回了void.请尝试返回Task,而不是
| 归档时间: |
|
| 查看次数: |
1299 次 |
| 最近记录: |