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
        private static void Initialization()
        {
            // Setup NLog
            // enable internal logging to a file
            NLog.Common.InternalLogger.LogLevel = LogLevel.Trace;
            NLog.Common.InternalLogger.LogFile  = Application.persistentDataPath + Path.DirectorySeparatorChar + "nlog-internal.log";

            ConfigurationItemFactory
            .Default
            .Targets
            .RegisterDefinition("UnityConsole", typeof(NLogUnityConsoleTarget));
            GlobalDiagnosticsContext.Set("platform", Application.platform.ToString());
            Debug.Log($"Platform is {GlobalDiagnosticsContext.Get("platform")}");
            GlobalDiagnosticsContext.Set("device", SystemInfo.deviceType);
            Debug.Log($"device is {GlobalDiagnosticsContext.Get("device")}");
            var config = new LoggingConfiguration()
                         .AddSentry(o =>
            {
                // Optionally specify a separate format for message
                o.Layout = "${message}";
                // Optionally specify a separate format for breadcrumbs
                o.BreadcrumbLayout = "${longdate}|${level:uppercase=true}|${logger}|${message}";

                // Debug and higher are stored as breadcrumbs (default is Info)
                o.MinimumBreadcrumbLevel = LogLevel.Debug;
                // Error and higher is sent as event (default is Error)
                o.MinimumEventLevel = LogLevel.Error;

                // Send the logger name as a tag
                o.AddTag("logger", "${logger}");
                o.AddTag("platform", GlobalDiagnosticsContext.Get("platform"));
                o.AddTag("device", GlobalDiagnosticsContext.Get("device"));
                o.Dsn = new Dsn("https://[email protected]/5600526");
                o.MinimumBreadcrumbLevel = LogLevel.Debug;
                o.MinimumEventLevel      = LogLevel.Error;
                // All Sentry Options are accessible here.
            });

            config.AddRule(LogLevel.Debug, LogLevel.Fatal, new NLog.Targets.FileTarget("logfile")
            {
                Name              = "file",
                FileName          = Application.persistentDataPath + Path.DirectorySeparatorChar + "${shortdate}-nlog-test.log",
                ArchiveNumbering  = NLog.Targets.ArchiveNumberingMode.Date,
                ArchiveEvery      = NLog.Targets.FileArchivePeriod.Day,
                ArchiveDateFormat = "yyyyMMdd",
                KeepFileOpen      = true,
                ConcurrentWrites  = false
            });
            config.AddRule(LogLevel.Debug, LogLevel.Fatal, new NLogUnityConsoleTarget());
            LogManager.Configuration = config;
            Debug.Log($"Loggin to {string.Join(", ", LogManager.Configuration.AllTargets)}");
        }
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
 /// <summary>
 ///
 /// </summary>
 protected override void Append(StringBuilder builder, LogEventInfo logEvent)
 {
     if (IsEnabled)
     {
         var controllerName  = GlobalDiagnosticsContext.Get(LoggerExceptionHandler.CONTROLLER_CONTEXT_KEY);
         var actionName      = GlobalDiagnosticsContext.Get(LoggerExceptionHandler.ACTION_CONTEXT_KEY);
         var actionArguments = GlobalDiagnosticsContext.Get(LoggerExceptionHandler.ACTION_ARGUMENTS_CONTEXT_KEY);
         builder.AppendLine();
         builder.AppendLine(String.Format(
                                "Action Arguments for {0}Controller.{1} =>",
                                controllerName == null ? "null" : controllerName,
                                actionName == null ? "null" : actionName));
         builder.AppendLine(actionArguments == null ? "null" : actionArguments);
     }
     else
     {
         builder.AppendLine();
         builder.AppendLine("Action argument logging disabled.");
     }
     GlobalDiagnosticsContext.Clear();
 }
Beispiel #5
0
 /// <summary>
 ///   Gets or sets the value of a property
 /// </summary>
 /// <value>
 ///   The value for the property with the specified key
 /// </value>
 /// <remarks>
 ///   <para>
 ///     Gets or sets the value of a property
 ///   </para>
 /// </remarks>
 public object this[string key]
 {
     get { return(GlobalDiagnosticsContext.Get(key)); }
     set { GlobalDiagnosticsContext.Set(key, value.ToString()); }
 }
Beispiel #6
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)
        {
            var msg = GlobalDiagnosticsContext.Get(Item);

            builder.Append(msg);
        }
Beispiel #7
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)
 {
     builder.Append(GlobalDiagnosticsContext.Get(this.Item, logEvent.FormatProvider));
 }
Beispiel #8
0
 public HomeData(IBibleTrainingConfig config)
     : base(config)
 {
     ApplicationName = GlobalDiagnosticsContext.Get("ApplicationName");
     DataApiBaseUrl  = config.DataApiBaseUrl;
 }