Exemplo n.º 1
0
        public void MatchesNameAndGuid()
        {
            // Arrange & Act
            Type eventSourceType = typeof(AzureIdentityEventSource);

            // Assert
            Assert.NotNull(eventSourceType);
            Assert.AreEqual("Azure-Identity", EventSource.GetName(eventSourceType));
            Assert.AreEqual(Guid.Parse("50c8e6e8-b11b-5998-63f4-3944e66d312a"), EventSource.GetGuid(eventSourceType));
            Assert.IsNotEmpty(EventSource.GenerateManifest(eventSourceType, "assemblyPathToIncludeInManifest"));
        }
Exemplo n.º 2
0
        public static void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(Dns).GetTypeInfo().Assembly.GetType("System.Net.NetEventSource", throwOnError: true, ignoreCase: false);

            Assert.NotNull(esType);

            Assert.Equal("Microsoft-System-Net-NameResolution", EventSource.GetName(esType));
            Assert.Equal(Guid.Parse("5f302add-3825-520e-8fa0-627b206e2e7e"), EventSource.GetGuid(esType));

            Assert.NotEmpty(EventSource.GenerateManifest(esType, "assemblyPathToIncludeInManifest"));
        }
Exemplo n.º 3
0
        public static void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(HttpClient).Assembly.GetType("System.Net.Http.HttpTelemetry", throwOnError: true, ignoreCase: false);

            Assert.NotNull(esType);

            Assert.Equal("System.Net.Http", EventSource.GetName(esType));
            Assert.Equal(Guid.Parse("d30b5633-7ef1-5485-b4e0-94979b102068"), EventSource.GetGuid(esType));

            Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
        }
Exemplo n.º 4
0
        public void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(SmtpClient).Assembly.GetType("System.Net.NetEventSource", throwOnError: true, ignoreCase: false);

            Assert.NotNull(esType);

            Assert.Equal("Private.InternalDiagnostics.System.Net.Mail", EventSource.GetName(esType));
            Assert.Equal(Guid.Parse("6fff04ac-5aab-530c-03b3-b1b32d2538e9"), EventSource.GetGuid(esType));

            Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
        }
Exemplo n.º 5
0
        public void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(IPAddress).Assembly.GetType("System.Net.NetEventSource", throwOnError: true, ignoreCase: false);

            Assert.NotNull(esType);

            Assert.Equal("Microsoft-System-Net-Primitives", EventSource.GetName(esType));
            Assert.Equal(Guid.Parse("a9f9e4e1-0cf5-5005-b530-3d37959d5e84"), EventSource.GetGuid(esType));

            Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
        }
Exemplo n.º 6
0
        public void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(WebHeaderCollection).Assembly.GetType("System.Net.NetEventSource", throwOnError: true, ignoreCase: false);

            Assert.NotNull(esType);

            Assert.Equal("Microsoft-System-Net-WebHeaderCollection", EventSource.GetName(esType));
            Assert.Equal(Guid.Parse("fd36452f-9f2b-5850-d212-6c436231e3dc"), EventSource.GetGuid(esType));

            Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
        }
Exemplo n.º 7
0
        public void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(SslStream).Assembly.GetType("System.Net.NetEventSource", throwOnError: true, ignoreCase: false);

            Assert.NotNull(esType);

            Assert.Equal("Private.InternalDiagnostics.System.Net.Security", EventSource.GetName(esType));
            Assert.Equal(Guid.Parse("a0d627f0-c0f5-5a45-558a-6634a894c155"), EventSource.GetGuid(esType));

            Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
        }
Exemplo n.º 8
0
        public static void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(Socket).Assembly.GetType("System.Net.NetEventSource", throwOnError: true, ignoreCase: false);

            Assert.NotNull(esType);

            Assert.Equal("Private.InternalDiagnostics.System.Net.Sockets", EventSource.GetName(esType));
            Assert.Equal(Guid.Parse("ae391de7-a2cb-557c-dd34-fe00d0b98c7f"), EventSource.GetGuid(esType));

            Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
        }
Exemplo n.º 9
0
        public static void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(Socket).Assembly.GetType("System.Net.Sockets.SocketsTelemetry", throwOnError: true, ignoreCase: false);

            Assert.NotNull(esType);

            Assert.Equal("System.Net.Sockets", EventSource.GetName(esType));
            Assert.Equal(Guid.Parse("d5b2e7d4-b6ec-50ae-7cde-af89427ad21f"), EventSource.GetGuid(esType));

            Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
        }
Exemplo n.º 10
0
        public void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(SmtpClient).Assembly.GetType("System.Net.NetEventSource", throwOnError: true, ignoreCase: false);

            Assert.NotNull(esType);

            Assert.Equal("Microsoft-System-Net-Mail", EventSource.GetName(esType));
            Assert.Equal(Guid.Parse("42c8027b-f048-58d2-537d-a4a9d5ee7038"), EventSource.GetGuid(esType));

            Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
        }
Exemplo n.º 11
0
        public static void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(HttpClient).GetTypeInfo().Assembly.GetType("System.Net.NetEventSource", throwOnError: true, ignoreCase: false);

            Assert.NotNull(esType);

            Assert.Equal("Microsoft-System-Net-Http", EventSource.GetName(esType));
            Assert.Equal(Guid.Parse("bdd9a83e-1929-5482-0d73-2fe5e1c0e16d"), EventSource.GetGuid(esType));

            Assert.NotEmpty(EventSource.GenerateManifest(esType, "assemblyPathToIncludeInManifest"));
        }
Exemplo n.º 12
0
        public void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(WebRequest).Assembly.GetType("System.Net.NetEventSource", throwOnError: true, ignoreCase: false);

            Assert.NotNull(esType);

            Assert.Equal("Microsoft-System-Net-Requests", EventSource.GetName(esType));
            Assert.Equal(Guid.Parse("3763dc7e-7046-5576-9041-5616e21cc2cf"), EventSource.GetGuid(esType));

            Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
        }
Exemplo n.º 13
0
        public static void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(Socket).Assembly.GetType("System.Net.NetEventSource", throwOnError: true, ignoreCase: false);

            Assert.NotNull(esType);

            Assert.Equal("Microsoft-System-Net-Sockets", EventSource.GetName(esType));
            Assert.Equal(Guid.Parse("e03c0352-f9c9-56ff-0ea7-b94ba8cabc6b"), EventSource.GetGuid(esType));

            Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
        }
Exemplo n.º 14
0
        public static void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(Dns).Assembly.GetType("System.Net.NameResolutionTelemetry", throwOnError: true, ignoreCase: false);

            Assert.NotNull(esType);

            Assert.Equal("System.Net.NameResolution", EventSource.GetName(esType));
            Assert.Equal(Guid.Parse("4b326142-bfb5-5ed3-8585-7714181d14b0"), EventSource.GetGuid(esType));

            Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
        }
Exemplo n.º 15
0
        public void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(NetworkChange).Assembly.GetType("System.Net.NetEventSource", throwOnError: false, ignoreCase: false);

            if (esType != null)
            {
                Assert.Equal("Microsoft-System-Net-NetworkInformation", EventSource.GetName(esType));
                Assert.Equal(Guid.Parse("b8e42167-0eb2-5e39-97b5-acaca593d3a2"), EventSource.GetGuid(esType));

                Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
            }
        }
Exemplo n.º 16
0
        public void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(NetworkChange).Assembly.GetType("System.Net.NetEventSource", throwOnError: false, ignoreCase: false);

            if (esType != null)
            {
                Assert.Equal("Private.InternalDiagnostics.System.Net.NetworkInformation", EventSource.GetName(esType));
                Assert.Equal(Guid.Parse("e090a35b-1033-5de3-89e3-01cde7c158ce"), EventSource.GetGuid(esType));

                Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
            }
        }
Exemplo n.º 17
0
        public void MatchesNameAndGuid()
        {
            // Arrange & Act
            var eventSourceType = typeof(WebHost).GetTypeInfo().Assembly.GetType(
                "Microsoft.AspNetCore.Hosting.Internal.HostingEventSource",
                throwOnError: true,
                ignoreCase: false);

            // Assert
            Assert.NotNull(eventSourceType);
            Assert.Equal("Microsoft-AspNetCore-Hosting", EventSource.GetName(eventSourceType));
            Assert.Equal(Guid.Parse("9e620d2a-55d4-5ade-deb7-c26046d245a8"), EventSource.GetGuid(eventSourceType));
            Assert.NotEmpty(EventSource.GenerateManifest(eventSourceType, "assemblyPathToIncludeInManifest"));
        }
Exemplo n.º 18
0
        public void ExistsWithCorrectId()
        {
            var esType = typeof(KestrelServer).Assembly.GetType(
                "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.KestrelEventSource",
                throwOnError: true,
                ignoreCase: false
                );

            Assert.NotNull(esType);

            Assert.Equal("Microsoft-AspNetCore-Server-Kestrel", EventSource.GetName(esType));
            Assert.Equal(Guid.Parse("bdeb4676-a36e-5442-db99-4764e2326c7d"), EventSource.GetGuid(esType));
            Assert.NotEmpty(EventSource.GenerateManifest(esType, "assemblyPathToIncludeInManifest"));
        }
Exemplo n.º 19
0
        public void EventWithPayloadAndMessageWithDateTimeFormatInXml()
        {
            var formatter = new XmlEventTextFormatter();

            formatter.DateTimeFormat = "dd/MM/yyyy";
            var logger = MockEventSrcForXml.Logger;

            string rawOutput = string.Empty;

            using (var listener = new InMemoryEventListener(formatter))
            {
                listener.EnableEvents(logger, EventLevel.LogAlways, MockEventSrcForXml.Keywords.Errors);
                try
                {
                    logger.LogUsingMessage(MockEventSrcForXml.LogMessage);
                    rawOutput = Encoding.Default.GetString(listener.Stream.ToArray());
                }
                finally
                {
                    listener.DisableEvents(logger);
                }
            }

            var entries = XDocument.Parse("<Events>" + rawOutput + "</Events>").Root.Elements();

            XmlFormattedEntry.Fill(entries.First());
            Assert.IsFalse(rawOutput.StartsWith("{\r\n")); // No Formatting (Default)
            string today    = System.DateTime.Today.ToString(formatter.DateTimeFormat);
            string tomorrow = System.DateTime.Today.AddDays(1).ToString("dd/MM/yyyy");

            Assert.IsTrue(rawOutput.Contains(today) || rawOutput.Contains(tomorrow));
            Assert.AreEqual <Guid>(EventSource.GetGuid(typeof(MockEventSrcForXml)), Guid.Parse(XmlFormattedEntry.Provider.Attribute("Guid").Value));
            Assert.AreEqual <int>(MockEventSrcForXml.LogUsingMessageEventID, Convert.ToInt32(XmlFormattedEntry.EventId.Value));
            Assert.AreEqual <byte>(0, Convert.ToByte(XmlFormattedEntry.Version.Value));
            Assert.AreEqual <int>((int)EventLevel.Informational, Int32.Parse(XmlFormattedEntry.Level.Value));
            Assert.AreEqual <int>((int)MockEventSrcForXml.Tasks.Page, Int32.Parse(XmlFormattedEntry.Task.Value));
            Assert.AreEqual <long>((long)EventKeywords.None, Int64.Parse(XmlFormattedEntry.Keywords.Value.Replace("0x", string.Empty)));
            Assert.AreEqual <int>((int)EventOpcode.Start, Int32.Parse(XmlFormattedEntry.Opcode.Value));
            Assert.AreEqual <byte>(0, Convert.ToByte(XmlFormattedEntry.Version.Value));
            Assert.AreEqual <int>(System.Diagnostics.Process.GetCurrentProcess().Id, Int32.Parse(XmlFormattedEntry.ProcessId.Value));
            Assert.AreEqual <int>(ThreadHelper.GetCurrentUnManagedThreadId(), Int32.Parse(XmlFormattedEntry.ThreadId.Value));
            DateTime dt;

            Assert.IsTrue(DateTime.TryParseExact(XmlFormattedEntry.TimeCreated.Attribute("SystemTime").Value, formatter.DateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt));
            Assert.AreEqual(1, XmlFormattedEntry.Payload.Elements().Count());
            Assert.AreEqual("message", XmlFormattedEntry.Payload.Elements().First().Attribute("Name").Value);
            Assert.AreEqual(MockEventSrcForXml.LogMessage, XmlFormattedEntry.Payload.Elements().First().Value);
            Assert.AreEqual(MockEventSrcForXml.LogMessage, XmlFormattedEntry.Message.Elements().First().Value);
        }
Exemplo n.º 20
0
        public void EventWithPayloadKeywrdsNoMsgInXml()
        {
            var logger    = MockEventSrcForXml.Logger;
            var formatter = new XmlEventTextFormatter();

            string rawOutput = string.Empty;

            using (var listener = new InMemoryEventListener(formatter))
            {
                listener.EnableEvents(logger, EventLevel.LogAlways, MockEventSrcForXml.Keywords.Errors);
                try
                {
                    logger.UsingKeywords(MockEventSrcForXml.LogMessage, long.MaxValue);
                    rawOutput = listener.ToString();
                }
                finally
                {
                    listener.DisableEvents(logger);
                }
            }

            Assert.AreEqual(-1, rawOutput.IndexOf("\r\n"));
            var entries = XDocument.Parse("<Events>" + rawOutput + "</Events>").Root.Elements();

            XmlFormattedEntry.Fill(entries.Single());
            Assert.AreEqual <Guid>(EventSource.GetGuid(typeof(MockEventSrcForXml)), Guid.Parse(XmlFormattedEntry.Provider.Attribute("Guid").Value));
            Assert.AreEqual <int>(MockEventSrcForXml.UsingKeywordsEventID, Convert.ToInt32(XmlFormattedEntry.EventId.Value));
            Assert.AreEqual <byte>(0, Convert.ToByte(XmlFormattedEntry.Version.Value));
            Assert.AreEqual <int>((int)EventLevel.Informational, Int32.Parse(XmlFormattedEntry.Level.Value));
            Assert.AreEqual <int>((int)MockEventSrcForXml.Tasks.DBQuery, Int32.Parse(XmlFormattedEntry.Task.Value));
            Assert.AreEqual <long>((long)MockEventSrcForXml.Keywords.Errors, Int64.Parse(XmlFormattedEntry.Keywords.Value.Replace("0x", string.Empty)));
            Assert.AreEqual <int>((int)EventOpcode.Start, Int32.Parse(XmlFormattedEntry.Opcode.Value));
            Assert.AreEqual <int>(System.Diagnostics.Process.GetCurrentProcess().Id, Int32.Parse(XmlFormattedEntry.ProcessId.Value));
            Assert.AreEqual <int>(ThreadHelper.GetCurrentUnManagedThreadId(), Int32.Parse(XmlFormattedEntry.ThreadId.Value));
            DateTime dt;

            Assert.IsTrue(DateTime.TryParseExact(XmlFormattedEntry.TimeCreated.Attribute("SystemTime").Value, EventEntry.DefaultDateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt));
            Assert.AreEqual(2, XmlFormattedEntry.Payload.Elements().Count());
            Assert.AreEqual("message", XmlFormattedEntry.Payload.Elements().First().Attribute("Name").Value);
            Assert.AreEqual(MockEventSrcForXml.LogMessage, XmlFormattedEntry.Payload.Elements().First().Value);
            Assert.AreEqual("longArg", XmlFormattedEntry.Payload.Elements().Last().Attribute("Name").Value);
            Assert.AreEqual(long.MaxValue.ToString(), XmlFormattedEntry.Payload.Elements().Last().Value);
        }
        public void EventWithPayloadAloneInXml()
        {
            var    formatter  = new XmlEventTextFormatter();
            string payloadMsg = ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<test/>");
            var    logger     = MockEventSrcForXml.Logger;

            string rawOutput = string.Empty;

            using (var listener = new InMemoryEventListener(formatter))
            {
                listener.EnableEvents(logger, EventLevel.LogAlways, MockEventSrcForXml.Keywords.Errors);
                try
                {
                    logger.LogUsingMessage(payloadMsg);
                    rawOutput = Encoding.Default.GetString(listener.Stream.ToArray());
                }
                finally
                {
                    listener.DisableEvents(logger);
                }
            }

            var entries = XDocument.Parse("<Events>" + rawOutput + "</Events>").Root.Elements();

            XmlFormattedEntry.Fill(entries.First());
            Assert.IsFalse(rawOutput.StartsWith("{\r\n")); // No Formatting (Default)
            Assert.AreEqual <Guid>(EventSource.GetGuid(typeof(MockEventSrcForXml)), Guid.Parse(XmlFormattedEntry.Provider.Attribute("Guid").Value));
            Assert.AreEqual <int>(MockEventSrcForXml.LogUsingMessageEventID, Convert.ToInt32(XmlFormattedEntry.EventId.Value));
            Assert.AreEqual <byte>(0, Convert.ToByte(XmlFormattedEntry.Version.Value));
            Assert.AreEqual <int>((int)EventLevel.Informational, Int32.Parse(XmlFormattedEntry.Level.Value));
            Assert.AreEqual <int>((int)EventTask.None, Int32.Parse(XmlFormattedEntry.Task.Value));
            Assert.AreEqual <long>((long)EventKeywords.None, Int64.Parse(XmlFormattedEntry.Keywords.Value.Replace("0x", string.Empty)));
            Assert.AreEqual <int>((int)EventOpcode.Start, Int32.Parse(XmlFormattedEntry.Opcode.Value));
            Assert.AreEqual <byte>(0, Convert.ToByte(XmlFormattedEntry.Version.Value));
            DateTime dt;

            Assert.IsTrue(DateTime.TryParseExact(XmlFormattedEntry.TimeCreated.Attribute("SystemTime").Value, EventEntry.DefaultDateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt));
            Assert.AreEqual(1, XmlFormattedEntry.Payload.Elements().Count());
            Assert.AreEqual("message", XmlFormattedEntry.Payload.Elements().First().Attribute("Name").Value);
            Assert.AreEqual(payloadMsg, XmlFormattedEntry.Payload.Elements().First().Value);
        }
Exemplo n.º 22
0
        public void EventWithPayloadKeywrdsNoMessageInJson()
        {
            var logger = MockEventSrcForJson.Logger;

            string rawOutput = string.Empty;

            using (var listener = new InMemoryEventListener()
            {
                Formatter = new JsonEventTextFormatter()
            })
            {
                listener.EnableEvents(logger, EventLevel.LogAlways, MockEventSrcForJson.Keywords.Errors);
                try
                {
                    logger.UsingKeywords(MockEventSrcForJson.LogMessage, long.MaxValue);
                    rawOutput = Encoding.Default.GetString(listener.Stream.ToArray());
                }
                finally
                {
                    listener.DisableEvents(logger);
                }
            }

            var entries = JsonConvert.DeserializeObject <TestEventEntry[]>("[" + rawOutput + "]");
            var entry   = entries.First();

            Assert.IsFalse(rawOutput.StartsWith("{\r\n")); // No Formatting (Default)
            Assert.AreEqual <Guid>(EventSource.GetGuid(typeof(MockEventSrcForJson)), entry.ProviderId);
            Assert.AreEqual <int>(MockEventSrcForJson.UsingKeywordsEventID, entry.EventId);
            Assert.AreEqual <EventLevel>(EventLevel.Informational, entry.Level);
            Assert.AreEqual <string>("None", entry.EventKeywords.ToString());
            Assert.AreEqual <EventOpcode>(EventOpcode.Start, entry.Opcode);
            Assert.AreEqual <int>(System.Diagnostics.Process.GetCurrentProcess().Id, entry.ProcessId);
            Assert.AreEqual <int>(ThreadHelper.GetCurrentUnManagedThreadId(), entry.ThreadId);
            Assert.AreEqual <byte>(0, entry.Version);
            Assert.AreEqual <EventTask>(MockEventSrcForJson.Tasks.DBQuery, entry.Task);
            Assert.AreEqual(null, entry.Message);
            Assert.AreEqual(2, entry.Payload.Count);
            StringAssert.Contains(entry.Payload.First().ToString(), MockEventSrcForJson.LogMessage);
            StringAssert.Contains(entry.Payload.Last().ToString(), long.MaxValue.ToString());
        }
        public void EventWithPayloadKeywrdsNoMsgIndentedInJson()
        {
            var logger = MockEventSrcForJson.Logger;

            string rawOutput = string.Empty;

            using (var listener = new InMemoryEventListener()
            {
                Formatter = new JsonEventTextFormatter(EventTextFormatting.Indented)
            })
            {
                listener.EnableEvents(logger, EventLevel.LogAlways, MockEventSrcForJson.Keywords.Errors);
                try
                {
                    logger.UsingKeywords(MockEventSrcForJson.LogMessage, long.MaxValue);
                    rawOutput = Encoding.Default.GetString(listener.Stream.ToArray());
                }
                finally
                {
                    listener.DisableEvents(logger);
                }
            }

            Assert.AreEqual(17, rawOutput.Split('\n').Length); //Assert is indented
            var entries = JsonConvert.DeserializeObject <TestEventEntry[]>("[" + rawOutput + "]");
            var entry   = entries.First();

            Assert.AreEqual <Guid>(EventSource.GetGuid(typeof(MockEventSrcForJson)), entry.ProviderId);
            Assert.AreEqual <int>(MockEventSrcForJson.UsingKeywordsEventID, entry.EventId);
            Assert.AreEqual <EventLevel>(EventLevel.Informational, entry.Level);
            Assert.AreEqual <string>("None", entry.EventKeywords.ToString());
            Assert.AreEqual <EventOpcode>(EventOpcode.Start, entry.Opcode);
            Assert.AreEqual <byte>(0, entry.Version);
            Assert.AreEqual <EventTask>(EventTask.None, entry.Task);
            Assert.AreEqual(null, entry.Message);
            Assert.AreEqual(2, entry.Payload.Count);
            StringAssert.Contains(entry.Payload.First().ToString(), MockEventSrcForJson.LogMessage);
            StringAssert.Contains(entry.Payload.Last().ToString(), long.MaxValue.ToString());
        }
        public void EventWithPayloadAndMessageInJson()
        {
            var logger = MockEventSrcForJson.Logger;

            string rawOutput = string.Empty;

            using (var listener = new InMemoryEventListener()
            {
                Formatter = new JsonEventTextFormatter()
            })
            {
                listener.EnableEvents(logger, EventLevel.LogAlways, MockEventSrcForJson.Keywords.Errors);
                try
                {
                    logger.LogUsingMessage(MockEventSrcForJson.LogMessage);
                    rawOutput = Encoding.Default.GetString(listener.Stream.ToArray());
                }
                finally
                {
                    listener.DisableEvents(logger);
                }
            }

            var entries = JsonConvert.DeserializeObject <TestEventEntry[]>("[" + rawOutput + "]");
            var entry   = entries.First();

            Assert.IsFalse(rawOutput.StartsWith("{\r\n")); // No Formatting (Default)
            Assert.AreEqual <Guid>(EventSource.GetGuid(typeof(MockEventSrcForJson)), entry.ProviderId);
            Assert.AreEqual <int>(MockEventSrcForJson.LogUsingMessageEventID, entry.EventId);
            Assert.AreEqual <EventLevel>(EventLevel.Informational, entry.Level);
            Assert.AreEqual <EventKeywords>(EventKeywords.None, entry.EventKeywords);
            Assert.AreEqual <EventOpcode>(EventOpcode.Start, entry.Opcode);
            Assert.AreEqual <byte>(0, entry.Version);
            Assert.AreEqual <EventTask>(EventTask.None, entry.Task);
            Assert.AreEqual(MockEventSrcForJson.LogMessage, entry.Message);
            Assert.AreEqual(1, entry.Payload.Count);
            StringAssert.Contains(entry.Payload.First().ToString(), MockEventSrcForJson.LogMessage);
        }
Exemplo n.º 25
0
        public void EventWithActivityIdAndRelatedActivityIdInXml()
        {
            var formatter = new XmlEventTextFormatter();
            var logger    = MockEventSrcForXml.Logger;

            var    activityId         = Guid.NewGuid();
            var    relatedActivityId  = Guid.NewGuid();
            var    previousActivityId = Guid.Empty;
            string rawOutput          = string.Empty;

            using (var listener = new InMemoryEventListener(formatter))
            {
                listener.EnableEvents(logger, EventLevel.LogAlways, MockEventSrcForXml.Keywords.Errors);
                try
                {
                    EventSource.SetCurrentThreadActivityId(activityId, out previousActivityId);
                    logger.LogUsingMessageWithRelatedActivityId(MockEventSrcForXml.LogMessage, relatedActivityId);
                    rawOutput = Encoding.Default.GetString(listener.Stream.ToArray());
                }
                finally
                {
                    listener.DisableEvents(logger);
                    EventSource.SetCurrentThreadActivityId(previousActivityId);
                }
            }

            var entries = XDocument.Parse("<Events>" + rawOutput + "</Events>").Root.Elements();

            XmlFormattedEntry.Fill(entries.First());
            Assert.AreEqual <Guid>(EventSource.GetGuid(typeof(MockEventSrcForXml)), Guid.Parse(XmlFormattedEntry.Provider.Attribute("Guid").Value));
            Assert.AreEqual(1, XmlFormattedEntry.Payload.Elements().Count());
            Assert.AreEqual("message", XmlFormattedEntry.Payload.Elements().First().Attribute("Name").Value);
            Assert.AreEqual(MockEventSrcForXml.LogMessage, XmlFormattedEntry.Payload.Elements().First().Value);
            Assert.AreEqual <Guid>(activityId, Guid.Parse(XmlFormattedEntry.Correlation.Attribute("ActivityID").Value));
            Assert.AreEqual <Guid>(relatedActivityId, Guid.Parse(XmlFormattedEntry.Correlation.Attribute("RelatedActivityID").Value));
        }
Exemplo n.º 26
0
 /// <summary>
 /// get roslyn event source guid
 /// </summary>
 public static Guid GetRoslynEventSourceGuid()
 {
     return(EventSource.GetGuid(typeof(RoslynEventSource)));
 }
Exemplo n.º 27
0
        public static JobDescription Create(Type jobType)
        {
            var attr     = JobAttribute.Get(jobType);
            var descAttr = jobType.GetCustomAttribute <DescriptionAttribute>();

            return(new JobDescription(
                       name: attr.Name,
                       description: descAttr == null ? null : descAttr.Description,
                       eventProviderId: attr.EventProvider == null ? (Guid?)null : (Guid?)EventSource.GetGuid(attr.EventProvider),
                       implementation: jobType));
        }