S
Solomon_Man
All,
I have a Windows Service application that has database connectivity
and needs the capability to let a user know that there has been a db
failure. What is the proper way to notify a user that there has been
error within a service?
I was thinking of writing to a file and using the below code;
public void LogMessageToFile(string msg)
{
//get current directory and then prepare to create a file
name Logger.txt
string Dir = Directory.GetCurrentDirectory();
System.IO.StreamWriter sw = System.IO.File.AppendText(
Directory.GetCurrentDirectory() + "Logger.txt");
try
{
//include the time of error
string logLine = System.String.Format(
"{0:G}: {1}.", System.DateTime.Now, msg);
sw.WriteLine(logLine); //write the string to file
sw.Flush();
}
finally //clean up after myself
{
sw.Close();
}
}
Unfortunately this code does not seem to write to a file when in a
windows service. It seems to work fine in a Windows form. Any ideas or
approaches?
Thanks,
Chris
I have a Windows Service application that has database connectivity
and needs the capability to let a user know that there has been a db
failure. What is the proper way to notify a user that there has been
error within a service?
I was thinking of writing to a file and using the below code;
public void LogMessageToFile(string msg)
{
//get current directory and then prepare to create a file
name Logger.txt
string Dir = Directory.GetCurrentDirectory();
System.IO.StreamWriter sw = System.IO.File.AppendText(
Directory.GetCurrentDirectory() + "Logger.txt");
try
{
//include the time of error
string logLine = System.String.Format(
"{0:G}: {1}.", System.DateTime.Now, msg);
sw.WriteLine(logLine); //write the string to file
sw.Flush();
}
finally //clean up after myself
{
sw.Close();
}
}
Unfortunately this code does not seem to write to a file when in a
windows service. It seems to work fine in a Windows form. Any ideas or
approaches?
Thanks,
Chris