Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Log(string line)
- {
- var sw = new StreamWriter(File.Open(
- "LogFile.log", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None));
- sw.WriteLine(line);
- // Since we don't close the stream the FileStream finalizer will do that for
- // us but we don't know when that will be and until then the file is locked.
- }
- public void Log(string line)
- {
- using (var sw = new StreamWriter(File.Open(
- "LogFile.log", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))) {
- sw.WriteLine(line);
- }
- // Since we use the using block (which conveniently calls Dispose() for us)
- // the file well be closed at this point.
- }
Add Comment
Please, Sign In to add comment