Exemplo n.º 1
0
        /// <summary>Format the log message into the format used by this log.</summary>
        protected override string FormatLogMessage(
            DateTime timestamp,
            Logger.Severity severity,
            TraceLogger.LoggerType loggerType,
            string caller,
            string message,
            IPEndPoint myIPEndPoint,
            Exception exception,
            int errorCode)
        {
            // Don't include stack trace in Warning messages for Console output.
            bool includeStackTrace = severity <= Logger.Severity.Error;

            if (!useCompactConsoleOutput)
            {
                return(base.FormatLogMessage_Impl(timestamp, severity, loggerType, caller, message, myIPEndPoint, exception, errorCode, includeStackTrace));
            }

            string msg = String.Format(logFormat,
                                       TraceLogger.PrintTime(timestamp),                                                                                    //0
                                       TraceLogger.SeverityTable[(int)severity],                                                                            //1
                                       errorCode,                                                                                                           //2
                                       caller,                                                                                                              //3
                                       message,                                                                                                             //4
                                       includeStackTrace ? TraceLogger.PrintException(exception) : TraceLogger.PrintExceptionWithoutStackTrace(exception)); //5

            return(msg);
        }
Exemplo n.º 2
0
 public void Close()
 {
     if (_logOutput == null)
     {
         return;                     // was already closed.
     }
     try
     {
         lock (_lockObj)
         {
             if (_logOutput == null) // was already closed.
             {
                 return;
             }
             _logOutput.Flush();
             _logOutput.Close();
         }
     }
     catch (Exception exc)
     {
         var msg = string.Format("Ignoring error closing log file {0} - {1}", _logFileName,
                                 TraceLogger.PrintException(exc));
         Console.WriteLine(msg);
     }
     finally
     {
         _logOutput   = null;
         _logFileName = null;
     }
 }
Exemplo n.º 3
0
        protected string FormatLogMessage_Impl(
            DateTime timestamp,
            Logger.Severity severity,
            TraceLogger.LoggerType loggerType,
            string caller,
            string message,
            IPEndPoint myIPEndPoint,
            Exception exception,
            int errorCode,
            bool includeStackTrace)
        {
            if (severity == Logger.Severity.Error)
            {
                message = "!!!!!!!!!! " + message;
            }

            string ip = myIPEndPoint == null ? String.Empty : myIPEndPoint.ToString();

            if (loggerType.Equals(TraceLogger.LoggerType.Grain))
            {
                // Grain identifies itself, so I don't want an additional long string in the prefix.
                // This is just a temporal solution to ease the dev. process, can remove later.
                ip = String.Empty;
            }
            string exc = includeStackTrace ? TraceLogger.PrintException(exception) : TraceLogger.PrintExceptionWithoutStackTrace(exception);
            string msg = String.Format("[{0} {1,5}\t{2}\t{3}\t{4}\t{5}]\t{6}\t{7}",
                                       TraceLogger.ShowDate ? TraceLogger.PrintDate(timestamp) : TraceLogger.PrintTime(timestamp), //0
                                       Thread.CurrentThread.ManagedThreadId,                                                       //1
                                       TraceLogger.SeverityTable[(int)severity],                                                   //2
                                       errorCode,                                                                                  //3
                                       caller,                                                                                     //4
                                       ip,                                                                                         //5
                                       message,                                                                                    //6
                                       exc);                                                                                       //7

            return(msg);
        }
Exemplo n.º 4
0
 public void Close()
 {
     if (logOutput == null)
     {
         return;                    // was already closed.
     }
     try
     {
         lock (lockObj)
         {
             if (logOutput == null) // was already closed.
             {
                 return;
             }
             logOutput.Flush();
             logOutput.Dispose();
         }
     }
     catch (Exception exc)
     {
         string msg = string.Format("Ignoring error closing log file {0} - {1}", logFileName, TraceLogger.PrintException(exc));
         Console.WriteLine(msg);
     }
     this.logOutput   = null;
     this.logFileName = null;
 }