Exemple #1
0
 public static IEnumerable <KeyValuePair <string, string> > FormatTagsWithTypeSuffix(this IEnumerable <KeyValuePair <string, object> > tags)
 {
     foreach (var tag in tags)
     {
         EventFieldFormatter.SerializeFieldValueAndTypeSuffix(tag.Value, out string value, out string suffix);
         yield return(new KeyValuePair <string, string>(prefix + tag.Key + suffix, value));
     }
 }
Exemple #2
0
        protected override Task <bool> WriteLog(TraceEventType severity, LogCallSiteInfo logCallSiteInfo, string message, IDictionary <string, string> encryptedTags, IDictionary <string, string> unencryptedTags, Exception exception = null, string stackTrace = null)
        {
            var entry = new LogEntry
            {
                Severity        = severity,
                Message         = message,
                EncryptedTags   = encryptedTags.ToDictionary(_ => _.Key, _ => EventFieldFormatter.SerializeFieldValue(_.Value)),
                UnencryptedTags = unencryptedTags.ToDictionary(_ => _.Key, _ => EventFieldFormatter.SerializeFieldValue(_.Value)),
                Exception       = exception
            };

            lock (LogEntriesList)
            {
                LogEntriesList.Add(entry);
            }

            return(null);
        }
Exemple #3
0
        protected override Task <bool> WriteLog(TraceEventType level, LogCallSiteInfo logCallSiteInfo,
                                                string message, IDictionary <string, string> encryptedTags, IDictionary <string, string> unencryptedTags,
                                                Exception exception = null, string stackTrace = null)
        {
            var logLevel = ToLogLevel(level);

            if (Log.Logger.IsEnabled(logLevel))
            {
                var messageWithTags = message + " " + string.Join(", ", unencryptedTags.Select(kvp => $"{kvp.Key.Substring(5)}={EventFieldFormatter.SerializeFieldValue(kvp.Value)}")) + ". ";
                Log.Logger.Write(logLevel, exception, messageWithTags);
            }

            return(Task.FromResult(true));
        }
        protected virtual string FormatLogEntry(TraceEventType severity, string message, List <KeyValuePair <string, string> > tags, Exception exception)
        {
            var sb = new StringBuilder(DateTime.Now.ToString("[HH:mm:ss.fff] "));

            switch (severity)
            {
            case TraceEventType.Critical:
                sb.Append("CRITICAL ");
                break;

            case TraceEventType.Error:
                sb.Append("ERROR    ");
                break;

            case TraceEventType.Warning:
                sb.Append("WARNING  ");
                break;

            case TraceEventType.Information:
                sb.Append("INFO     ");
                break;

            case TraceEventType.Verbose:
                sb.Append("DEBUG    ");
                break;
            }

            if (message != null)
            {
                sb.Append(message);
            }



            if (!HideTags && tags.Count > 0)
            {
                sb.Append(" { ");

                foreach (var tag in tags)
                {
                    sb.Append($"{tag.Key}={EventFieldFormatter.SerializeFieldValue(tag.Value)}, ");
                }

                sb.Remove(sb.Length - 2, 2);
                sb.Append(" }");
            }

            if (exception != null)
            {
                if (sb.Length > 0)
                {
                    sb.AppendLine();
                }

                if (HideExceptionStackTrace)
                {
                    sb.Append($"{exception.GetType().Namespace}: {exception.Message}");
                }
                else
                {
                    sb.Append(exception);
                }
            }


            return(sb.ToString());
        }
Exemple #5
0
 public static IEnumerable <KeyValuePair <string, string> > FormatTagsWithoutTypeSuffix(this IEnumerable <KeyValuePair <string, object> > tags)
 {
     return(tags.Select(tag => new KeyValuePair <string, string>(prefix + tag.Key, EventFieldFormatter.SerializeFieldValue(tag.Value))));
 }