Ejemplo n.º 1
0
        private static LogBuilder Create(LogLevel logLevel, string callerFilePath)
        {
            var logger  = GetLogger(callerFilePath);
            var builder = new LogBuilder(logger, logLevel);

            return(builder);
        }
Ejemplo n.º 2
0
        public static LogBuilder Tag(this LogBuilder builder, params string[] tags)
        {
            var tagList = builder.LogEventInfo.GetTags();

            tagList.AddRange(tags);

            return(builder);
        }
Ejemplo n.º 3
0
        public static LogBuilder ContextProperty(this LogBuilder builder, string key, object value)
        {
            var contextData = builder.LogEventInfo.GetContextData();

            contextData[key] = value;

            return(builder);
        }
Ejemplo n.º 4
0
        public static LogBuilder Organization(this LogBuilder builder, string organizationId)
        {
            if (String.IsNullOrEmpty(organizationId))
            {
                return(builder);
            }

            return(builder.Property("organization", organizationId));
        }
Ejemplo n.º 5
0
        public static LogBuilder Project(this LogBuilder builder, string projectId)
        {
            if (String.IsNullOrEmpty(projectId))
            {
                return(builder);
            }

            return(builder.Property("project", projectId));
        }
Ejemplo n.º 6
0
Archivo: Log.cs Proyecto: zuohu/NLog
        private static LogBuilder Create(LogLevel logLevel, string callerFilePath)
        {
            string name = Path.GetFileNameWithoutExtension(callerFilePath ?? string.Empty);
            var logger = string.IsNullOrWhiteSpace(name) ? _logger : LogManager.GetLogger(name);

            var builder = new LogBuilder(logger, logLevel);
            if (callerFilePath != null)
                builder.Property("CallerFilePath", callerFilePath);

            return builder;
        }
Ejemplo n.º 7
0
        public static LogBuilder MarkUnhandled(this LogBuilder builder, string submissionMethod = null)
        {
            var contextData = builder.LogEventInfo.GetContextData();

            contextData.MarkAsUnhandledError();
            if (!String.IsNullOrEmpty(submissionMethod))
            {
                contextData.SetSubmissionMethod(submissionMethod);
            }

            return(builder);
        }
Ejemplo n.º 8
0
        private static LogBuilder Create(LogLevel logLevel, string callerFilePath)
        {
            var logger  = GetLogger(callerFilePath);
            var builder = new LogBuilder(logger, logLevel);

            if (callerFilePath != null)
            {
                builder.Property("CallerFilePath", callerFilePath);
            }

            return(builder);
        }
Ejemplo n.º 9
0
        public static LogBuilder Report(this LogBuilder builder, Action <ErrorBuilder> errorBuilderAction = null)
        {
            if (builder.LogEventInfo.Exception != null)
            {
                ErrorBuilder exBuilder = builder.LogEventInfo.Exception.ToExceptionless();

                if (errorBuilderAction != null)
                {
                    errorBuilderAction(exBuilder);
                }

                exBuilder.Submit();
            }

            return(builder);
        }
Ejemplo n.º 10
0
        public static LogBuilder Tag(this LogBuilder builder, IEnumerable <string> tags)
        {
            var tagList = new List <string>();

            if (builder.LogEventInfo.Properties.ContainsKey("tags") && builder.LogEventInfo.Properties["tags"] is List <string> )
            {
                tagList = builder.LogEventInfo.Properties["tags"] as List <string>;
            }

            foreach (string tag in tags)
            {
                if (!tagList.Any(s => s.Equals(tag, StringComparison.OrdinalIgnoreCase)))
                {
                    tagList.Add(tag);
                }
            }

            return(builder.Property("tags", tagList));
        }
        public static LogBuilder Report(this LogBuilder builder, Action <EventBuilder> errorBuilderAction = null)
        {
            if (builder.LogEventInfo.Exception != null)
            {
                EventBuilder exBuilder = builder.LogEventInfo.Exception.ToExceptionless();

                if (errorBuilderAction != null)
                {
                    errorBuilderAction(exBuilder);
                }

                exBuilder.AddObject(builder.LogEventInfo, name: "Log Info", excludedPropertyNames: new List <string> {
                    "Exception", "Message", "LoggerShortName", "SequenceID", "TimeStamp"
                });

                exBuilder.Submit();
            }

            return(builder);
        }
Ejemplo n.º 12
0
 public static LogBuilder Error(this ILogger logger)
 {
     var builder = new LogBuilder(logger, LogLevel.Error);
     return builder;
 }
Ejemplo n.º 13
0
        public static LogBuilder Info(this ILogger logger)
        {
            var builder = new LogBuilder(logger, LogLevel.Info);

            return(builder);
        }
Ejemplo n.º 14
0
        private static LogBuilder Create(LogLevel logLevel, string callerFilePath)
        {
            string name = Path.GetFileNameWithoutExtension(callerFilePath ?? string.Empty);
            var logger = string.IsNullOrWhiteSpace(name) ? _logger : LogManager.GetLogger(name);

            var builder = new LogBuilder(logger, logLevel);
            if (callerFilePath != null)
                builder.Property("CallerFilePath", callerFilePath);

            return builder;
        }
Ejemplo n.º 15
0
        public static LogBuilder Trace(this ILogger logger)
        {
            var builder = new LogBuilder(logger, LogLevel.Trace);

            return(builder);
        }
Ejemplo n.º 16
0
        public static LogBuilder Debug(this ILogger logger)
        {
            var builder = new LogBuilder(logger, LogLevel.Debug);

            return(builder);
        }
Ejemplo n.º 17
0
 public static LogBuilder Critical(this LogBuilder builder, bool isCritical = true)
 {
     return(isCritical ? builder.Tag(Event.KnownTags.Critical) : builder);
 }
Ejemplo n.º 18
0
        public static LogBuilder Log(this ILogger logger, LogLevel logLevel)
        {
            var builder = new LogBuilder(logger, logLevel);

            return(builder);
        }
Ejemplo n.º 19
0
        public static LogBuilder Warn(this ILogger logger)
        {
            var builder = new LogBuilder(logger, LogLevel.Warn);

            return(builder);
        }
Ejemplo n.º 20
0
        public static LogBuilder Error(this ILogger logger)
        {
            var builder = new LogBuilder(logger, LogLevel.Error);

            return(builder);
        }
Ejemplo n.º 21
0
 public static LogBuilder Project(this LogBuilder builder, string projectId)
 {
     return(builder.Property("project", projectId));
 }
Ejemplo n.º 22
0
 public static LogBuilder Organization(this LogBuilder builder, string organizationId)
 {
     return(builder.Property("organization", organizationId));
 }
Ejemplo n.º 23
0
 public static LogBuilder Info(this ILogger logger)
 {
     var builder = new LogBuilder(logger, LogLevel.Info);
     return builder;
 }
Ejemplo n.º 24
0
 public static LogBuilder Trace(this ILogger logger)
 {
     var builder = new LogBuilder(logger, LogLevel.Trace);
     return builder;
 }
Ejemplo n.º 25
0
 public static LogBuilder Critical(this LogBuilder builder, bool isCritical = true)
 {
     return(isCritical ? builder.Tag("Critical") : builder);
 }
Ejemplo n.º 26
0
 public static LogBuilder Fatal(this ILogger logger)
 {
     var builder = new LogBuilder(logger, LogLevel.Fatal);
     return builder;
 }
Ejemplo n.º 27
0
        public static LogBuilder Fatal(this ILogger logger)
        {
            var builder = new LogBuilder(logger, LogLevel.Fatal);

            return(builder);
        }
Ejemplo n.º 28
0
 public static LogBuilder Log(this ILogger logger, LogLevel logLevel)
 {
     var builder = new LogBuilder(logger, logLevel);
     return builder;
 }
Ejemplo n.º 29
0
 public static LogBuilder Tag(this LogBuilder builder, string tag)
 {
     return(builder.Tag(new[] { tag }));
 }
Ejemplo n.º 30
0
 public static LogBuilder Debug(this ILogger logger)
 {
     var builder = new LogBuilder(logger, LogLevel.Debug);
     return builder;
 }
Ejemplo n.º 31
0
        public void LogBuilder_null_lead_to_ArgumentNullException()
        {
            var logger = LogManager.GetLogger("a");
            Assert.Throws<ArgumentNullException>(() => new LogBuilder(null, LogLevel.Debug));
            Assert.Throws<ArgumentNullException>(() => new LogBuilder(null));
            Assert.Throws<ArgumentNullException>(() => new LogBuilder(logger, null));

            var logBuilder = new LogBuilder(logger);
            Assert.Throws<ArgumentNullException>(() => logBuilder.Properties(null));
            Assert.Throws<ArgumentNullException>(() => logBuilder.Property(null, "b"));

        }
Ejemplo n.º 32
0
 public static LogBuilder Warn(this ILogger logger)
 {
     var builder = new LogBuilder(logger, LogLevel.Warn);
     return builder;
 }
Ejemplo n.º 33
0
        public void LogBuilder_nLogEventInfo()
        {
            var d = new DateTime(2015, 01, 30, 14, 30, 5);
            var logEventInfo = new LogBuilder(LogManager.GetLogger("a")).LoggerName("b").Level(LogLevel.Fatal).TimeStamp(d).LogEventInfo;

            Assert.Equal("b", logEventInfo.LoggerName);
            Assert.Equal(LogLevel.Fatal, logEventInfo.Level);
            Assert.Equal(d, logEventInfo.TimeStamp);
        }