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 Log(
            Logger.Severity severity,
            TraceLogger.LoggerType loggerType,
            string caller,
            string message,
            IPEndPoint myIPEndPoint,
            Exception exception,
            int errorCode)
        {
            var now = DateTime.UtcNow;

            var msg = FormatLogMessage(
                now,
                severity,
                loggerType,
                caller,
                message,
                myIPEndPoint,
                exception,
                errorCode);

            try
            {
                WriteLogMessage(msg, severity);
            }
            catch (Exception exc)
            {
                Trace.TraceError("Error writing log message {0} -- Exception={1}", msg, exc);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// The method to call during logging to format the log info into a string ready for output.
 /// </summary>
 /// <param name="severity">The severity of the message being traced.</param>
 /// <param name="loggerType">The type of logger the message is being traced through.</param>
 /// <param name="caller">The name of the logger tracing the message.</param>
 /// <param name="myIPEndPoint">The <see cref="IPEndPoint"/> of the Orleans client/server if known. May be null.</param>
 /// <param name="message">The message to log.</param>
 /// <param name="exception">The exception to log. May be null.</param>
 /// <param name="eventCode">Numeric event code for this log entry. May be zero, meaning 'Unspecified'.</param>
 protected virtual string FormatLogMessage(
     DateTime timestamp,
     Logger.Severity severity,
     TraceLogger.LoggerType loggerType,
     string caller,
     string message,
     IPEndPoint myIPEndPoint,
     Exception exception,
     int errorCode)
 {
     return(FormatLogMessage_Impl(timestamp, severity, loggerType, caller, message, myIPEndPoint, exception, errorCode, true));
 }
Exemplo n.º 4
0
        public void Log(Severity severity, TraceLogger.LoggerType loggerType, string caller, string message, System.Net.IPEndPoint myIPEndPoint, Exception exception, int eventCode = 0)
        {
            lock (this)
            {
                if (entryCounts.ContainsKey(eventCode))
                {
                    entryCounts[eventCode]++;
                }
                else
                {
                    entryCounts.Add(eventCode, 1);
                }

                if (eventCode != lastLogCode)
                {
                    output.WriteLine("{0} {1} - {2}", severity, eventCode, message);
                    lastLogCode = eventCode;
                }
            }
        }
Exemplo n.º 5
0
        private static string GetLogTypeTag(TraceLogger.LoggerType loggerType)
        {
            switch (loggerType)
            {
            case global::Orleans.Runtime.TraceLogger.LoggerType.Grain:
                return("Orleans Grain Trace Log");

            case global::Orleans.Runtime.TraceLogger.LoggerType.Application:
                return("Orleans Application Trace Log");

            case global::Orleans.Runtime.TraceLogger.LoggerType.Provider:
                return("Orleans Provider Trace Log");

            case global::Orleans.Runtime.TraceLogger.LoggerType.Runtime:
                return("Orleans Runtime Trace Log");

            default:
                return("Orleans Trace Log");
            }
        }
Exemplo n.º 6
0
        public static string FormatLogMessage(
            Severity severity,
            TraceLogger.LoggerType loggerType,
            string caller,
            string message,
            IPEndPoint myIPEndPoint,
            Exception exception,
            int errorCode)
        {
            var now = DateTime.UtcNow;

            return(FormatLogMessage(
                       now,
                       severity,
                       loggerType,
                       caller,
                       message,
                       myIPEndPoint,
                       exception,
                       errorCode));
        }
Exemplo n.º 7
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.º 8
0
 public Logger GetLogger(string loggerName, TraceLogger.LoggerType logType)
 {
     return(TraceLogger.GetLogger(loggerName, logType));
 }
Exemplo n.º 9
0
        /// <summary>
        ///     The method to call during logging to format the log info into a string ready for output.
        /// </summary>
        /// <param name="timestamp">The timestamp.</param>
        /// <param name="severity">The severity of the message being traced.</param>
        /// <param name="loggerType">The type of logger the message is being traced through.</param>
        /// <param name="caller">The name of the logger tracing the message.</param>
        /// <param name="message">The message to log.</param>
        /// <param name="myIPEndPoint">The <see cref="T:System.Net.IPEndPoint" /> of the Orleans client/server if known. May be null.</param>
        /// <param name="exception">The exception to log. May be null.</param>
        /// <param name="errorCode">Numeric event code for this log entry. May be zero, meaning 'Unspecified'.</param>
        /// <returns>System.String.</returns>
        protected override string FormatLogMessage(DateTime timestamp, Logger.Severity severity, TraceLogger.LoggerType loggerType, string caller, string message, IPEndPoint myIPEndPoint, Exception exception, int errorCode)
        {
            string tag = GetLogTypeTag(loggerType);

            if (errorCode < 0)
            {
                errorCode = -errorCode;
            }

            Dictionary <string, object> payload = new Dictionary <string, object>
            {
                { "IpEndPoint", myIPEndPoint?.ToString() },
                { "SourceSeverity", severity },
                { "SourceTimestamp", timestamp }
            };

            MessageContent messageContent = BuildLogMessageContent(
                $"{caller}: {message}", tag, Convert.ToUInt64(errorCode), string.Empty, null, exception, payload);

            return(messageContent.ToJson());
        }