title: Best way to track Windows Service Unhandled Exception
body: <p>I have a Windows Service application. The service is basically copying Excel files to a directory at specific hours, then reading Excel rows and finally updating SQL Server tables according to the data in the row it reads.</p>
  <p>Recently, it crashes sometimes. While I was reviewing logs, I found it crashed because:</p>
  <blockquote>
  <p>Application: WinCCServiceIzmit.exe Framework Version: v4.0.30319
  Description: The process was terminated due to an unhandled exception.</p>
  <p>Exception Info: System.IO.IOException</p>
  <p>at System.IO.__Error.WinIOError(Int32, System.String)<br />
  at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean, Boolean)<br />
  at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, Int32, System.IO.FileOptions, System.String, Boolean, Boolean, Boolean)<br />
  at System.IO.StreamWriter.CreateFile(System.String, Boolean, Boolean)<br />
  at System.IO.StreamWriter..ctor(System.String, Boolean, System.Text.Encoding, Int32, Boolean)<br />
  at System.IO.StreamWriter..ctor(System.String, Boolean)<br />
  at System.IO.File.AppendText(System.String)<br />
  at WinccService.InnerOperation.WriteToFile(System.String)<br />
  at WinccService.InnerOperation.Stop()<br />
  at WinccService.WinccIzmit.start()<br />
  at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)<br />
  at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)<br />
  at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)<br />
  at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)<br />
  at System.Threading.ThreadHelper.ThreadStart()</p>
  </blockquote>
  <p>Do you guys have any idea how can I track where the problem comes from? Application has too many code rows.</p>
  <p>Thanks.</p>