Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I handled this by adding try/catch to my project</p> <pre><code>try { using (Stream stream = new FileStream(@"\log.txt", FileMode.Open)) { //Write to your log file here } } catch (Exception ex) { //you can check here why it failed } </code></pre> <p>In the catch method you can use ex.Message and an if-statement to handle it. For example... <em>MyError here will be I/O File Doesn't Exist or File In Use but you can test that easily yourself</em></p> <p>Take not that in the below snippet you will create a new logfile in the same location that has the date in the name. This way you are certain that have a unique filename and it is easy to go through the logfiles if you are searching for issues.</p> <pre><code>if (ex.Message == "MyError") { string filename = String.Format("{1}_{0:yyyy-MM-dd}", @"log", DateTime.Now); string fullpath = Path.Combine(@"\",filename); using (StreamWriter sw = File.CreateText(path)) { //This is where you will write your text to the new file if the other one was in use sw.WriteLine("something...."); } } </code></pre> <p><strong>EDIT:</strong></p> <p>See here for exceptions for filehandling that you can use in the Exception handling, using the exception handling will make sure your application doesn't crash.</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.io.filenotfoundexception(v=vs.71).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.io.filenotfoundexception(v=vs.71).aspx</a></p> <p>Hope this helps.</p> <p>Cheers, Kevin</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload