Missing error handling in Streaming-AJAX-Proxy Log
- by Michael Freidgeim
We are using AjaxProxy(FROM http://www.codeproject.com/KB/ajax/ajaxproxy.aspx)
on our web site, but started to notice errors accessing log.txt file.
I found that the file is created by Log class and doesn't have ability to switch it off and error handling.
I've added reading file name from configuration and try/catch block
public static class Log
{
private static StreamWriter logStream;
private static object lockObject = new object ();
public static void WriteLine(string msg)
{
string logFileName = ConfigurationExtensions.GetAppSetting("AjaxStreamingProxy.LogFile" ,"");
if (logFileName.IsNullOrEmpty())
return;
try
{
if (logStream == null )
{
lock (lockObject)
{
if (logStream == null )
{
logStream = File.AppendText(Path .Combine(AppDomain.CurrentDomain.BaseDirectory, logFileName));
}
}
}
logStream.WriteLine(msg);
}
catch (Exception exc)
{
string ignoredMsg = String .Format("The error occured while logging {0}, but processing will continue.\n {1} ", exc);
LoggerHelper.LogEvent(ignoredMsg, MyCategorySource, TraceEventType .Warning, true);
}
}