Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Object mLogLock = new Object(); //to make logging thread safe
- string mLogFile = ""; //set your log location
- string mLogDirectory = "";
- public void HandleMessage(string inMessage)
- {
- lock (mLogLock)
- {
- if (!System.IO.Directory.Exists(mLogDirectory ))
- {
- System.IO.Directory.CreateDirectory(mLogDirectory );
- }
- String theMessage = DateTime.Now.ToString("s");
- if (inMessage != null)
- theMessage += " : " + inMessage;
- StreamWriter sw = new StreamWriter(mLogFile, true);
- sw.WriteLine(theMessage );
- sw.Dispose();
- sw.Close();
- }
- }
Add Comment
Please, Sign In to add comment