Esempio n. 1
0
        private void WriteLogMessage(int errorCode, Severity sev, string format, object[] args, Exception exception)
        {
            string message = FormatMessageText(format, args);

            bool logMessageTruncated = false;

            if (message.Length > LogManager.MAX_LOG_MESSAGE_SIZE)
            {
                message             = $"{message.Substring(0, LogManager.MAX_LOG_MESSAGE_SIZE)}. MESSAGE TRUNCATED AT THIS POINT!! Max message size = {LogManager.MAX_LOG_MESSAGE_SIZE}";
                logMessageTruncated = true;
            }

            foreach (ILogConsumer consumer in LogManager.LogConsumers)
            {
                try
                {
                    consumer.Log(sev, loggerType, Name, message, LogManager.MyIPEndPoint, exception, errorCode);

                    if (logMessageTruncated)
                    {
                        consumer.Log(Severity.Warning, loggerType, Name,
                                     "Previous log message was truncated - Max size = " + LogManager.MAX_LOG_MESSAGE_SIZE,
                                     LogManager.MyIPEndPoint, exception,
                                     (int)ErrorCode.Logger_LogMessageTruncated);
                    }
                }
                catch (Exception exc)
                {
                    Console.WriteLine("Exception while passing a log message to log consumer. Logger type:{0}, name:{1}, severity:{2}, message:{3}, error code:{4}, message exception:{5}, log consumer exception:{6}",
                                      consumer.GetType().FullName, Name, sev, message, errorCode, exception, exc);
                }
            }

            var formatedTraceMessage = TraceParserUtils.FormatLogMessage(sev, loggerType, Name, message, LogManager.MyIPEndPoint, exception, errorCode);

            if (exception != null)
            {
                TrackException(exception);
            }

            TrackTrace(formatedTraceMessage, sev);

            if (logMessageTruncated)
            {
                formatedTraceMessage = TraceParserUtils.FormatLogMessage(Severity.Warning, loggerType, Name,
                                                                         "Previous log message was truncated - Max size = " + LogManager.MAX_LOG_MESSAGE_SIZE,
                                                                         LogManager.MyIPEndPoint, exception,
                                                                         (int)ErrorCode.Logger_LogMessageTruncated);

                TrackTrace(formatedTraceMessage);
            }

            if ((DateTime.UtcNow - lastFlush) > flushInterval)
            {
                lastFlush = DateTime.UtcNow;
                LogManager.Flush();
            }
        }
 public void TrackException(Exception exception, IDictionary <string, string> properties = null, IDictionary <string, double> metrics = null)
 {
     ConsoleText.WriteError(TraceParserUtils.PrintProperties(exception.Message, properties), exception);
 }
 public void TrackTrace(string message, Severity severityLevel, IDictionary <string, string> properties = null)
 {
     TrackTrace(TraceParserUtils.PrintProperties(message, properties));
 }
 public void TrackTrace(string message, IDictionary <string, string> properties)
 {
     TrackTrace(TraceParserUtils.PrintProperties(message, properties));
 }