In my code, I wanted to write log exception to some file.
So I created a Utility class & wrote a static method in that to write log message to file.
Expand|Select|Wrap|Line Numbers
- public static void WriteLog(string message)
- {
- using (FileStream fs = new FileStream(@"c:\log.txt", FileMode.Append))
- {
- using (StreamWriter streamWriter = new StreamWriter(fs))
- {
- streamWriter.WriteLine(message);
- }
- }
- }
This works fine so far but I fear if two methods call this function simultaneously.. what will happen?
Also, I want to access this same Utility library in my other "WEB" projects... will it work there too?
Or else.. what will be the best way to log exceptions in any project?
Thanks in advance.
Zack