newbie question

K

Kuznetsov Dmitriy

Hello, I try to write message to log file
(I take code from MSDN samples)
but simple program:
---
using System.IO;
using System.Diagnostics;
class Test
{
public static void Main(string[] args)
{
string logFile = "Log.txt";
if(!File.Exists(logFile))
File.Create(logFile);

StreamWriter logStream = File.AppendText(logFile);

TextWriterTraceListener logListener =
new TextWriterTraceListener(logStream);
}
}

---

throws an exception:
System.IO.IOException: The process cannot access the file "Log.txt"
because it is being used by another process.


can anybody explain to me what wrong?
 
K

Kuznetsov Dmitriy

thank you.
Why File.Create holdon Log.txt if I don't use returned value (stream) in my
code
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top