Esempio n. 1
0
 public void Send(TraceEvent eventData)
 {
     try
     {
         if (eventData.MetaData != null && !string.IsNullOrEmpty(eventData.MetaData.MessageFormat))
         {
             // Check if trace message is sent to the portal (somewhere before in the stack)
             // It allows to avoid infinite recursion if sending to the portal traces something.
             if (!ThreadResourceLock.IsResourceLocked)
             {
                 using (var portalSenderLock = new ThreadResourceLock())
                 {
                     try
                     {
                         if (!this.throttlingManager.ThrottleEvent(eventData.MetaData.EventId, eventData.MetaData.Keywords))
                         {
                             this.InternalSendTraceTelemetry(eventData);
                         }
                     }
                     catch (Exception exp)
                     {
                         // This message will not be sent to the portal because we have infinite loop protection
                         // But it will be available in PerfView or StatusMonitor
                         CoreEventSource.Log.LogError("Failed to send traces to the portal: " + exp.ToInvariantString());
                     }
                 }
             }
         }
     }
     catch (Exception)
     {
         // We were trying to send traces out and failed.
         // No reason to try to trace something else again
     }
 }
 public void Send(TraceEvent eventData)
 {
     try
     {
         if (eventData.MetaData != null && !string.IsNullOrEmpty(eventData.MetaData.MessageFormat))
         {
             // Check if trace message is sended to the portal (somewhere before in the stack)
             // It allows to avoid infinite recursion if sending to the portal traces something.
             if (!ThreadResourceLock.IsResourceLocked)
             {
                 using (var portalSenderLock = new ThreadResourceLock())
                 {
                     try
                     {
                         if (!this.throttlingManager.ThrottleEvent(eventData.MetaData.EventId, eventData.MetaData.Keywords))
                         {
                             this.InternalSendTraceTelemetry(eventData);
                         }
                     }
                     catch (Exception exp)
                     {
                         // This message will not be sent to the portal because we have infinite loop protection
                         // But it will be available in PerfView or StatusMonitor
                         CoreEventSource.Log.LogError("Failed to send traces to the portal: " + exp.ToInvariantString());
                     }
                 }
             }
         }
     }
     catch (Exception)
     {
         // We were trying to send traces out and failed. 
         // No reason to try to trace something else again
     }
 }
Esempio n. 3
0
        public void LockIsSetOnSameThread()
        {
            Assert.IsFalse(ThreadResourceLock.IsResourceLocked);
            using (var resourceLock = new ThreadResourceLock())
            {
                Assert.IsTrue(ThreadResourceLock.IsResourceLocked);
            }

            Assert.IsFalse(ThreadResourceLock.IsResourceLocked);
        }
        public void LockIsSetOnSameThread()
        {
            Assert.IsFalse(ThreadResourceLock.IsResourceLocked);
            using (var resourceLock = new ThreadResourceLock())
            {
                Assert.IsTrue(ThreadResourceLock.IsResourceLocked);
            }

            Assert.IsFalse(ThreadResourceLock.IsResourceLocked);
        }
        public void LockNotSetOnDifferentThread()
        {
            Assert.IsFalse(ThreadResourceLock.IsResourceLocked);
            using (var resourceLock = new ThreadResourceLock())
            {
                Assert.IsTrue(ThreadResourceLock.IsResourceLocked);
                var otherThread = new Thread(new ThreadStart(() =>
                {
                    Assert.IsFalse(ThreadResourceLock.IsResourceLocked);
                    using (var internalResourceLock = new ThreadResourceLock())
                    {
                        Assert.IsTrue(ThreadResourceLock.IsResourceLocked);
                    }

                    Assert.IsFalse(ThreadResourceLock.IsResourceLocked);
                }));
                otherThread.Start();

                otherThread.Join();
                Assert.IsTrue(ThreadResourceLock.IsResourceLocked);
            }
        }