Missing error handling in Streaming-AJAX-Proxy Log
        Posted  
        
            by Michael Freidgeim
        on Geeks with Blogs
        
        See other posts from Geeks with Blogs
        
            or by Michael Freidgeim
        
        
        
        Published on Sat, 06 Oct 2012 01:49:12 GMT
        Indexed on 
            2012/10/09
            21:42 UTC
        
        
        Read the original article
        Hit count: 265
        
Filed under: 
        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);
                     }
        }
 © Geeks with Blogs or respective owner