Beispiel #1
0
        public void GDCTest1()
        {
            GlobalDiagnosticsContext.Clear();
            Assert.False(GlobalDiagnosticsContext.Contains("foo"));
            Assert.Equal(string.Empty, GlobalDiagnosticsContext.Get("foo"));
            Assert.False(GlobalDiagnosticsContext.Contains("foo2"));
            Assert.Equal(string.Empty, GlobalDiagnosticsContext.Get("foo2"));
            Assert.Equal(0, GlobalDiagnosticsContext.GetNames().Count);

            GlobalDiagnosticsContext.Set("foo", "bar");
            GlobalDiagnosticsContext.Set("foo2", "bar2");

            Assert.True(GlobalDiagnosticsContext.Contains("foo"));
            Assert.Equal("bar", GlobalDiagnosticsContext.Get("foo"));
            Assert.Equal(2, GlobalDiagnosticsContext.GetNames().Count);

            GlobalDiagnosticsContext.Remove("foo");
            Assert.False(GlobalDiagnosticsContext.Contains("foo"));
            Assert.Equal(string.Empty, GlobalDiagnosticsContext.Get("foo"));

            Assert.True(GlobalDiagnosticsContext.Contains("foo2"));
            Assert.Equal("bar2", GlobalDiagnosticsContext.Get("foo2"));

            Assert.Equal(1, GlobalDiagnosticsContext.GetNames().Count);

            Assert.Null(GlobalDiagnosticsContext.GetObject("foo3"));
            Assert.Equal(string.Empty, GlobalDiagnosticsContext.Get("foo3", null));

            GlobalDiagnosticsContext.Set("foo3", new { One = 1 });
            Assert.NotNull(GlobalDiagnosticsContext.Get("foo3", null));
        }
Beispiel #2
0
        void CreateChangeRequest_Common(object changeData)
        {
            LogThis(LogLevel.Debug, $"-> Initiating COMMON change handling ...");

            string localChangeID = GenerateChangeID();

            LogThis(LogLevel.Trace, $"Local Change ID generated: {localChangeID}L");

            List <object> changeDataList = (List <object>)changeData;

            bool      isChangeEventFireHandling = (bool)(changeDataList).ElementAt(0);
            object    sender = changeDataList.Count >= 2 ? (changeDataList).ElementAt(1) : null;
            EventArgs e      = changeDataList.Count >= 3 ? (EventArgs)(changeDataList).ElementAt(2) : null;

            LogThis(LogLevel.Trace, $"Event source type: {(isChangeEventFireHandling == true ? "Event Fire" : "Monitor Enable")}");

            if (isChangeEventFireHandling)
            {
                LogThis(LogLevel.Trace, $"Event sender: {(sender != null ? sender.ToString() : "null")}");
                LogThis(LogLevel.Trace, $"Event details: {(e != null ? e.GetType().ToString() : "null")}");
            }

            if (!Global.CurrentlyProcessingAChangeRequest)
            {
                lock (changeHandlerLock)
                {
                    Global.CurrentlyProcessingAChangeRequest = true;
                    LogThis(LogLevel.Trace, $"Got lock access: {localChangeID}L");
                    Global.ChangeIDBeingProcessed = localChangeID;
                    GlobalDiagnosticsContext.Set(Global.LoggingVarNames.ChangeId, localChangeID);
                    LogThis(LogLevel.Trace, "Global Change ID set");
                    UpdateSystemTrayIconAndTooltipOnly();
                    LogThis(LogLevel.Trace, "Starting change handling ...");
                    CheckForChangeAndPerformUpdatesIfNeeded();
                    LogThis(LogLevel.Trace, "Change handling ended. Releasing lock ...");
                    Global.ChangeIDBeingProcessed = null;

                    GlobalDiagnosticsContext.Remove(Global.LoggingVarNames.ChangeId);

                    Global.CurrentlyProcessingAChangeRequest = false;

                    RefreshSystemTrayMenu();
                }
            }
            else
            {
                Logger.Warn("Locked out: Another change being serviced: {changeID}");
            }

            LogThis(LogLevel.Debug, $"Change handling done - ending thread ...");

            Thread.CurrentThread.Abort(); //TODO: Check if this is the best way to end the thread
        }
Beispiel #3
0
        public void GDCTest1()
        {
            GlobalDiagnosticsContext.Clear();
            Assert.IsFalse(GlobalDiagnosticsContext.Contains("foo"));
            Assert.AreEqual(string.Empty, GlobalDiagnosticsContext.Get("foo"));
            Assert.IsFalse(GlobalDiagnosticsContext.Contains("foo2"));
            Assert.AreEqual(string.Empty, GlobalDiagnosticsContext.Get("foo2"));

            GlobalDiagnosticsContext.Set("foo", "bar");
            GlobalDiagnosticsContext.Set("foo2", "bar2");

            Assert.IsTrue(GlobalDiagnosticsContext.Contains("foo"));
            Assert.AreEqual("bar", GlobalDiagnosticsContext.Get("foo"));

            GlobalDiagnosticsContext.Remove("foo");
            Assert.IsFalse(GlobalDiagnosticsContext.Contains("foo"));
            Assert.AreEqual(string.Empty, GlobalDiagnosticsContext.Get("foo"));

            Assert.IsTrue(GlobalDiagnosticsContext.Contains("foo2"));
            Assert.AreEqual("bar2", GlobalDiagnosticsContext.Get("foo2"));
        }
Beispiel #4
0
        public void GDCTest()
        {
            LogManager.Configuration = XmlLoggingConfiguration.CreateFromXmlString(@"
            <nlog>
                <targets><target name='debug' type='Debug' layout='${gdc:item=myitem} ${message}' /></targets>
                <rules>
                    <logger name='*' minlevel='Debug' writeTo='debug' />
                </rules>
            </nlog>");

            GlobalDiagnosticsContext.Set("myitem", "myvalue");
            LogManager.GetLogger("A").Debug("a");
            AssertDebugLastMessage("debug", "myvalue a");

            GlobalDiagnosticsContext.Set("myitem", "value2");
            LogManager.GetLogger("A").Debug("b");
            AssertDebugLastMessage("debug", "value2 b");

            GlobalDiagnosticsContext.Remove("myitem");
            LogManager.GetLogger("A").Debug("c");
            AssertDebugLastMessage("debug", " c");
        }