public void FormatHttpRequestUrlTest()
        {
            var mockHttpTraceContext = new MockHttpTraceContext();

            mockHttpTraceContext.RequestUrl = new Uri("http://test/x");
            var traceFormatter = new TraceFormatter();

            traceFormatter.HttpTraceContext = mockHttpTraceContext;
            TraceListener   listener          = null;
            TraceEventCache eventCache        = null;
            string          source            = "test";
            TraceEventType  eventType         = TraceEventType.Warning;
            int             id                = 5;
            string          message           = "fnord";
            Guid?           relatedActivityId = null;

            object[] data     = null;
            string   template = "|{RequestUrl}|";
            string   expected = "|http://test/x|";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                                               message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        protected override void WriteTrace(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message, Guid?relatedActivityId, object[] data)
        {
            var output = String.IsNullOrEmpty(Template) ? message : traceFormatter.Format(Template,
                                                                                          this,
                                                                                          eventCache,
                                                                                          source,
                                                                                          eventType,
                                                                                          id,
                                                                                          message,
                                                                                          relatedActivityId,
                                                                                          data
                                                                                          );

            queueBuffer.Pend(new TraceMessage()
            {
                EventType         = eventType,
                TimeUtc           = eventCache == null ? DateTime.UtcNow : eventCache.DateTime.ToUniversalTime(),
                Message           = output,
                Callstack         = IncludeCallstack ? eventCache.Callstack : null,
                Id                = id,
                ProcessId         = eventCache == null ? new Nullable <int>() : eventCache.ProcessId,
                RelatedActivityId = relatedActivityId,
                Source            = source,
                ThreadId          = eventCache == null ? null : eventCache.ThreadId,

                Origin = InstanceId,
            });
        }
        public void FormatIdAndMessageTest()
        {
            var traceFormatter = new TraceFormatter();
            TraceListener listener = null;
            TraceEventCache eventCache = null;
            string source = "test";
            TraceEventType eventType = TraceEventType.Warning;
            int id = 5;
            string message = "fnord";
            Guid? relatedActivityId = null;
            object[] data = null;
            string template = "{Id}.{Message}";
            string expected = "5.fnord";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatProcessIdTest()
        {
            var             traceFormatter    = new TraceFormatter();
            TraceListener   listener          = null;
            TraceEventCache eventCache        = null;
            string          source            = "test";
            TraceEventType  eventType         = TraceEventType.Warning;
            int             id                = 5;
            string          message           = "fnord";
            Guid?           relatedActivityId = null;

            object[] data     = null;
            string   template = "{ProcessId}";
            string   expected = Process.GetCurrentProcess().Id.ToString();

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                                               message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatMessagePrefixSentinel()
        {
            var             traceFormatter    = new TraceFormatter();
            TraceEventCache eventCache        = null;
            TraceListener   listener          = null;
            string          source            = "test";
            TraceEventType  eventType         = TraceEventType.Warning;
            int             id                = 0;
            Guid?           relatedActivityId = null;

            object[] data     = null;
            string   template = "<{MessagePrefix}>";
            string   message  = "Something to say. the rest of the trace.";
            string   expected = "<Something to say>";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                                               message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatIdAndMessageTest()
        {
            var             traceFormatter    = new TraceFormatter();
            TraceListener   listener          = null;
            TraceEventCache eventCache        = null;
            string          source            = "test";
            TraceEventType  eventType         = TraceEventType.Warning;
            int             id                = 5;
            string          message           = "fnord";
            Guid?           relatedActivityId = null;

            object[] data     = null;
            string   template = "{Id}.{Message}";
            string   expected = "5.fnord";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                                               message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatEmptyHttpContextTest()
        {
            // The default is HttpContext.Current, which should be empty when running unit test
            var traceFormatter = new TraceFormatter();
            TraceListener listener = null;
            TraceEventCache eventCache = null;
            string source = "test";
            TraceEventType eventType = TraceEventType.Warning;
            int id = 5;
            string message = "fnord";
            Guid? relatedActivityId = null;
            object[] data = null;
            string template = "|{RequestUrl}|";
            string expected = "||";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                    message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatEmptyHttpContextTest()
        {
            // The default is HttpContext.Current, which should be empty when running unit test
            var             traceFormatter    = new TraceFormatter();
            TraceListener   listener          = null;
            TraceEventCache eventCache        = null;
            string          source            = "test";
            TraceEventType  eventType         = TraceEventType.Warning;
            int             id                = 5;
            string          message           = "fnord";
            Guid?           relatedActivityId = null;

            object[] data     = null;
            string   template = "|{RequestUrl}|";
            string   expected = "||";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                                               message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatHttpRequestUrlTest()
        {
            var mockHttpTraceContext  =new MockHttpTraceContext();
            mockHttpTraceContext.RequestUrl = new Uri("http://test/x");
            var traceFormatter = new TraceFormatter();
            traceFormatter.HttpTraceContext = mockHttpTraceContext;
            TraceListener listener = null;
            TraceEventCache eventCache = null;
            string source = "test";
            TraceEventType eventType = TraceEventType.Warning;
            int id = 5;
            string message = "fnord";
            Guid? relatedActivityId = null;
            object[] data = null;
            string template = "|{RequestUrl}|";
            string expected = "|http://test/x|";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                    message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatPrincipalNameTest()
        {
            var             traceFormatter    = new TraceFormatter();
            TraceListener   listener          = null;
            TraceEventCache eventCache        = null;
            string          source            = "test";
            TraceEventType  eventType         = TraceEventType.Warning;
            int             id                = 5;
            string          message           = "fnord";
            Guid?           relatedActivityId = null;

            object[] data     = null;
            string   template = "{Id}.{PrincipalName}";
            string   expected = "5.testuser";
            string   actual   = null;

            using (var scope = new UserResetScope("testuser"))
            {
                actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                                               message, relatedActivityId, data);
            }

            Assert.AreEqual(expected, actual);
        }
        public void FormatMessagePrefixAll()
        {
            var traceFormatter = new TraceFormatter();
            TraceEventCache eventCache = null;
            TraceListener listener = null;
            string source = "test";
            TraceEventType eventType = TraceEventType.Warning;
            int id = 0;
            Guid? relatedActivityId = null;
            object[] data = null;
            string template = "<{MessagePrefix}>";
            string message = "Something to say";

            string expected = "<Something to say>";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatProcessIdTest()
        {
            var traceFormatter = new TraceFormatter();
            TraceListener listener = null;
            TraceEventCache eventCache = null;
            string source = "test";
            TraceEventType eventType = TraceEventType.Warning;
            int id = 5;
            string message = "fnord";
            Guid? relatedActivityId = null;
            object[] data = null;
            string template = "{ProcessId}";
            string expected = Process.GetCurrentProcess().Id.ToString();

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                    message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatPrincipalNameTest()
        {
            var traceFormatter = new TraceFormatter();
            TraceListener listener = null;
            TraceEventCache eventCache = null;
            string source = "test";
            TraceEventType eventType = TraceEventType.Warning;
            int id = 5;
            string message = "fnord";
            Guid? relatedActivityId = null;
            object[] data = null;
            string template = "{Id}.{PrincipalName}";
            string expected = "5.testuser";
            string actual = null;

            using (var scope = new UserResetScope("testuser"))
            {
                actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                    message, relatedActivityId, data);
            }

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 14
0
 public override string ToString()
 {
     return(TraceFormatter.Format(error, data));
 }