Пример #1
0
 private void LoadGlobalDiagnosticsContextProperties(IDictionary <string, string> propertyBag)
 {
     foreach (string key in GlobalDiagnosticsContext.GetNames())
     {
         this.PopulatePropertyBag(propertyBag, key, GlobalDiagnosticsContext.GetObject(key));
     }
 }
Пример #2
0
        /// <summary>
        /// Renders the specified Global Diagnostics Context item and appends it to the specified <see cref="StringBuilder" />.
        /// </summary>
        /// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
        /// <param name="logEvent">Logging event.</param>
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            //don't use GlobalDiagnosticsContext.Get to ensure we are not locking the Factory (indirect by LogManager.Configuration).
            var o = GlobalDiagnosticsContext.GetObject(this.Item);

            builder.Append(o, logEvent, LoggingConfiguration);
        }
Пример #3
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));
        }
Пример #4
0
        /// <summary>
        /// Renders the specified Global Diagnostics Context item and appends it to the specified <see cref="StringBuilder" />.
        /// </summary>
        /// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
        /// <param name="logEvent">Logging event.</param>
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            //don't use GlobalDiagnosticsContext.Get to ensure we are not locking the Factory (indirect by LogManager.Configuration).
            var value          = GlobalDiagnosticsContext.GetObject(Item);
            var formatProvider = GetFormatProvider(logEvent, null);

            builder.AppendFormattedValue(value, null, formatProvider);
        }
Пример #5
0
 private object GetValue()
 {
     //don't use GlobalDiagnosticsContext.Get to ensure we are not locking the Factory (indirect by LogManager.Configuration).
     return(GlobalDiagnosticsContext.GetObject(Item));
 }