문제

If I uncomment this line of code in a project of mine, and comment out the one after it, occasionally I'll get the exception & stack trace:

System.InvalidOperationException: Operation is not valid due to the current state of the object
  at System.IO.StreamWriter.CheckState () [0x00000] in <filename unknown>:0 
  at System.IO.StreamWriter.WriteLineAsync (System.String value) [0x00000] in <filename unknown>:0 
  at System.IO.SynchronizedWriter.WriteLineAsync (System.String value) [0x00000] in <filename unknown>:0 
  at Gerty.Service+<PullJob>c__async1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at Gerty.Service+<Work>c__async0.MoveNext () [0x00000] in <filename unknown>:0 

I guess what's confusing me is that I'm getting this exception despite awaiting the statement.

도움이 되었습니까?

해결책

As things go, using Console.Out for debug information is eventually going to interfere with your program.

As of this posting, I feel that NLog is the best option for logging. Especially in asynchronous applications due to their non-blocking API and very simple configuration.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top