Example #1
0
 public static void OverrideDiagnosticsLevel(DiagnosticsLevels newLevel){
     _overrideLevel = newLevel;
 }
Example #2
0
 private static void AppendMessageToFile(Site site,HttpConnection conn,HttpRequest request, DiagnosticsLevels logLevel, string Message)
 {
     Monitor.Enter(_lock);
     _messages.Enqueue(_FormatDiagnosticsMessage(site,conn,request, logLevel, Message));
     Monitor.Exit(_lock);
 }
Example #3
0
 //formats a diagnostics message using the appropriate date time format as well as site and log level information
 private static string _FormatDiagnosticsMessage(Site site,HttpConnection conn,HttpRequest request, DiagnosticsLevels logLevel, string Message)
 {
     string sfs = "UNKNOWN";
     if (request != null)
         sfs = "HttpRequest[" + request.ID.ToString() + "]";
     else if (conn != null)
         sfs = "HttpConnection[" + conn.ID.ToString() + "]";
     else if (BackgroundOperationRun.Current != null)
         sfs = "BackgroundRunThread[" + BackgroundOperationRun.Current.ID.ToString() + "][" + BackgroundOperationRun.Current.Call.type.FullName + "." + BackgroundOperationRun.Current.Call.Method.Name + "]";
     else
     {
         try
         {
             sfs = "Thread[" + Thread.CurrentThread.Name + "]";
         }
         catch (Exception e) { }
     }
     if (site != null)
     {
         if (Settings.UseServerNameInLogging)
         {
             if (site.ServerName != null)
                 return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "|" + logLevel.ToString() + "|" + site.ServerName+"|"+sfs+"|" + Message;
             else if (conn!=null)
                 return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "|" + logLevel.ToString() + "|" + conn.Listener.IP.ToString() + ":" + conn.Listener.Port.ToString() + "|" + sfs + "|" + Message;
             else
                 return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "|" + logLevel.ToString() + "|" + site.ListenOn[0].Address.ToString() + ":" + site.ListenOn[0].Port.ToString() + "|" + sfs + "|" + Message;
         }else
             return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "|" + logLevel.ToString() + "|" + sfs + "|" + Message;
     }
     else if (conn != null)
     {
         if (Settings.UseServerNameInLogging)
             return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "|" + logLevel.ToString() + "|" + conn.Listener.IP.ToString() + ":" + conn.Listener.Port.ToString() + "|" + sfs + "|" + Message;
     }
     return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "|" + logLevel.ToString() + "|null|" + sfs + "|" + Message;
 }
Example #4
0
 /*
  * Called to log a message.  It checks if to check for site settings
  * for the log, or just general settings.  Once it has been determined if 
  * logging should occur, it then determines the type and either prints it
  * to the appropriate output, or it appends the message to the given queue asynchronously.
  */
 public static void LogMessage(DiagnosticsLevels logLevel, string Message)
 {
     DiagnosticsLevels lvl = DiagnosticsLevels.NONE;
     DiagnosticsOutputs opt = DiagnosticsOutputs.DEBUG;
     if (_overrideLevel.HasValue)
         lvl = _overrideLevel.Value;
     else if (Site.CurrentSite != null)
         lvl = Site.CurrentSite.DiagnosticsLevel;
     else
         lvl = Settings.DiagnosticsLevel;
     if (_overrideOutput.HasValue)
         opt = _overrideOutput.Value;
     else if (Site.CurrentSite != null)
         opt = Site.CurrentSite.DiagnosticsOutput;
     else
         opt = Settings.DiagnosticsOutput;
     if ((int)lvl >= (int)logLevel)
     {
         switch (opt)
         {
             case DiagnosticsOutputs.DEBUG:
                 System.Diagnostics.Debug.WriteLine(_FormatDiagnosticsMessage(Site.CurrentSite, HttpConnection.CurrentConnection,HttpRequest.CurrentRequest, logLevel, Message));
                 break;
             case DiagnosticsOutputs.CONSOLE:
                 Console.WriteLine(_FormatDiagnosticsMessage(Site.CurrentSite, HttpConnection.CurrentConnection,HttpRequest.CurrentRequest, logLevel, Message));
                 break;
             case DiagnosticsOutputs.FILE:
                 new delAppendMessageToFile(AppendMessageToFile).BeginInvoke(Site.CurrentSite, HttpConnection.CurrentConnection,HttpRequest.CurrentRequest, logLevel, Message, new AsyncCallback(QueueMessageComplete), null);
                 break;
             case DiagnosticsOutputs.SOCKET:
                 _sockLog.SendTo(System.Text.ASCIIEncoding.ASCII.GetBytes(_FormatDiagnosticsMessage(Site.CurrentSite, HttpConnection.CurrentConnection,HttpRequest.CurrentRequest, logLevel, Message) + "\n\n"), Site.CurrentSite.RemoteLoggingServer);
                 break;
         }
     }
 }