Esempio n. 1
0
 public void ProgramFailureTest()
 {
     using (DataLoggerEventSource itemToTest = DataLoggerEventSource.Log())
         using (EventListener lisner = new EventListener())
         {
             List <EventWrittenEventArgs> eventsList = new List <EventWrittenEventArgs>();
             lisner.EventWritten += (source, entry) => eventsList.Add(entry);
             Assert.AreEqual <int>(0, eventsList.Count);
             lisner.EnableEvents(itemToTest, EventLevel.LogAlways, EventKeywords.All);
             itemToTest.ProgramFailure("ClassName", "problem");
             Assert.AreEqual <int>(1, eventsList.Count);
             EventWrittenEventArgs eventArgs = eventsList[0];
             Assert.AreEqual <int>(1, eventArgs.EventId);
             Assert.AreEqual <string>("At ClassName.ProgramFailureTest encountered application failure: problem", String.Format(eventArgs.Message, eventArgs.Payload.Select <object, string>(x => x.ToString()).ToArray <string>()));
             Assert.AreEqual <EventChannel>(EventChannel.Admin, eventArgs.Channel);
             Assert.AreEqual <int>(1, eventArgs.EventId);
             Assert.AreEqual <string>(nameof(DataLoggerEventSource.ProgramFailure), eventArgs.EventName);
             Assert.AreSame(DataLoggerEventSource.Log(), eventArgs.EventSource);
             Assert.IsTrue((DataLoggerEventSource.Keywords.Diagnostic & eventArgs.Keywords) > 0);
             Assert.AreEqual <EventLevel>(EventLevel.Error, eventArgs.Level);
             Assert.AreEqual <EventOpcode>(EventOpcode.Info, eventArgs.Opcode);
             Assert.AreEqual <EventTask>(DataLoggerEventSource.Tasks.Code, eventArgs.Task);
             Assert.AreEqual <byte>(0x01, eventArgs.Version);
         }
 }
Esempio n. 2
0
        /// <summary>
        /// Logs the exception using <see cref="DataLoggerEventSource" />.
        /// </summary>
        /// <param name="eventSource">The event source to be used for problem reporting.</param>
        /// <param name="className">Name of the class where the exception has been caught.</param>
        /// <param name="e">The exception to be reported.</param>
        /// <param name="methodName">Name of the method.</param>
        internal static void LogException(this DataLoggerEventSource eventSource, string className, Exception e, [CallerMemberName] string methodName = nameof(LogException))
        {
            Exception _exception = e;
            string    _innerText = "An exception has been caught:";

            while (e != null)
            {
                eventSource.ProgramFailure(className, methodName, $"{_innerText} of type {_exception.GetType().Name} capturing the message: {e.Message}");
                e          = e.InnerException;
                _innerText = "It contains inner exception:";
            }
        }
Esempio n. 3
0
 public void ConstructorTest()
 {
     using (DataLoggerEventSource itemToTest = DataLoggerEventSource.Log())
     {
         Assert.IsNotNull(itemToTest);
         Assert.IsNull(itemToTest.ConstructionException);
         Assert.AreEqual <Guid>(Guid.Parse("B28CBA3C-E2B7-4C5B-A045-E21FD3158D9B"), itemToTest.Guid);
         Assert.AreEqual <string>("UAOOI.Networking.DataRepository.DataLogger.Diagnostic.DataLoggerEventSource", itemToTest.Name);
         Assert.AreEqual <EventSourceSettings>(EventSourceSettings.EtwManifestEventFormat, itemToTest.Settings);
         Assert.IsFalse(itemToTest.IsEnabled());
         Assert.AreSame(itemToTest, DataLoggerEventSource.Log());
     }
 }
Esempio n. 4
0
 public void DisposeTestMethod()
 {
     try
     {
         DataLoggerEventSource itemToTest = DataLoggerEventSource.Log();
         itemToTest.Dispose();
         Assert.IsNotNull(itemToTest);
         Assert.AreNotSame(itemToTest, DataLoggerEventSource.Log());
     }
     finally
     {
         DataLoggerEventSource.Log().Dispose();
     }
 }
Esempio n. 5
0
 public void EventListenerTest()
 {
     using (DataLoggerEventSource itemToTest = DataLoggerEventSource.Log())
         using (EventListener lisner = new EventListener())
         {
             List <EventSourceCreatedEventArgs> sourceList = new List <EventSourceCreatedEventArgs>();
             List <EventWrittenEventArgs>       eventsList = new List <EventWrittenEventArgs>();
             lisner.EventSourceCreated += (o, es) => sourceList.Add(es);
             lisner.EventWritten       += (source, entry) => eventsList.Add(entry);
             foreach (EventSourceCreatedEventArgs item in sourceList)
             {
                 Debug.WriteLine($"{item.EventSource.Name}:{item.EventSource.Guid}; Is enabled: {item.EventSource.IsEnabled()}");
             }
             int esCount = sourceList.Count;
             Assert.AreEqual <int>(0, eventsList.Count);
             lisner.EnableEvents(itemToTest, EventLevel.LogAlways, EventKeywords.All);
             Assert.AreEqual <int>(esCount, sourceList.Count);
             Assert.AreEqual <int>(0, eventsList.Count);
         }
 }
Esempio n. 6
0
 /// <summary>
 /// Gets the part event source.
 /// </summary>
 /// <returns>Returns an instance of <see cref="EventSource" />.</returns>
 public EventSource GetPartEventSource()
 {
     return(DataLoggerEventSource.Log());
 }