当前位置: 首页>>代码示例>>C#>>正文


C# Log.Trace方法代码示例

本文整理汇总了C#中Log.Trace方法的典型用法代码示例。如果您正苦于以下问题:C# Log.Trace方法的具体用法?C# Log.Trace怎么用?C# Log.Trace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Log的用法示例。


在下文中一共展示了Log.Trace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestConfiguration


//.........这里部分代码省略.........
        Logger = new Loggers.Null(),
        Properties = new[] { "Event.Type" },
        Filter = new Filter()
        {
           IncludeProps = new[] { new Filter.Property(null, "test") },
        }
     }
      ));
      AssertException(() => Log.RegisterInstance(
     new Instance()
     {
        Logger = new Loggers.Null(),
        Properties = new[] { "Event.Type" },
        Filter = new Filter()
        {
           IncludeProps = new[] { new Filter.Property("", "test") },
        }
     }
      ));
      AssertException(() => Log.RegisterInstance(
     new Instance()
     {
        Logger = new Loggers.Null(),
        Properties = new[] { "Event.Type" },
        Filter = new Filter()
        {
           IncludeProps = new[] { new Filter.Property(" ", "test") },
        }
     }
      ));
      AssertException(() => Log.RegisterInstance(
     new Instance()
     {
        Logger = new Loggers.Null(),
        Properties = new[] { "Event.Type" },
        Filter = new Filter()
        {
           ExcludeProps = new[] { new Filter.Property(null, "test") },
        }
     }
      ));
      AssertException(() => Log.RegisterInstance(
     new Instance()
     {
        Logger = new Loggers.Null(),
        Properties = new[] { "Event.Type" },
        Filter = new Filter()
        {
           ExcludeProps = new[] { new Filter.Property("", "test") },
        }
     }
      ));
      AssertException(() => Log.RegisterInstance(
     new Instance()
     {
        Logger = new Loggers.Null(),
        Properties = new[] { "Event.Type" },
        Filter = new Filter()
        {
           ExcludeProps = new[] { new Filter.Property(" ", "test") },
        }
     }
      ));
      // default instance registration
      var instance = new Instance()
      {
     Logger = queue,
     Synchronous = true,
     Buffer = 0,
     Properties = new[] { "Event.Type" }
      };
      Log.RegisterInstance(instance);
      log.Trace("trace");
      evt = queue.Dequeue().Single();
      Assert.AreEqual(evt["Event.Type"], EventType.Trace);
      Log.UnregisterInstance(instance);
      log.Trace("trace");
      Assert.IsFalse(queue.Dequeue().Any());
      // disposable instance registration
      using (
     Log.RegisterInstance(
        new Instance()
        {
           Logger = queue,
           Synchronous = true,
           Buffer = 0,
           Properties = new[] { "Event.Type" }
        }
     )
      )
      {
     log.Info("info");
     evt = queue.Dequeue().Single();
     Assert.AreEqual(evt["Event.Type"], EventType.Info);
      }
      log.Info("info");
      Assert.IsFalse(queue.Dequeue().Any());
      // log source type
      Assert.AreEqual(log.SourceType, GetType());
 }
开发者ID:modulexcite,项目名称:NLogEx,代码行数:101,代码来源:TestLog.cs

示例2: TestEventProperties

 public void TestEventProperties()
 {
     // configure the log
      var log = new Log(this);
      var queue = new Loggers.Queue();
      var props = new List<String>()
      {
     "Event.Type",
     "Event.Source",
     "Event.Timestamp",
     "Event.Time",
     "Event.Message",
     "Event.Exception",
      };
      using (
     Log.RegisterInstance(
        new Instance()
        {
           Logger = queue,
           Synchronous = true,
           Buffer = 0,
           Properties = props
        }
     )
      )
      {
     Event evt;
     // invalid property
     log.Trace("");
     evt = queue.Dequeue().Single();
     Assert.IsNull(evt[null]);
     Assert.IsNull(evt[""]);
     Assert.IsNull(evt[" "]);
     Assert.IsNull(evt["Invalid"]);
     Assert.IsNull(evt["Event.Invalid"]);
     // property list
     log.Error(new Exception("test"));
     evt = queue.Dequeue().Single();
     Assert.IsTrue(evt.Names.SequenceEqual(props));
     Assert.IsTrue(evt.Properties.Select(p => p.Key).SequenceEqual(props));
     Assert.IsTrue(!evt.Values.Any(v => v == null));
     Assert.IsTrue(!evt.Properties.Any(p => p.Value == null));
     // event type
     log.Trace("");
     evt = queue.Dequeue().Single();
     Assert.AreEqual(evt["Event.Type"], EventType.Trace);
     log.Info("");
     evt = queue.Dequeue().Single();
     Assert.AreEqual(evt["event.type"], EventType.Info);
     log.Warn("");
     evt = queue.Dequeue().Single();
     Assert.AreEqual(evt["Event.type"], EventType.Warning);
     log.Error("");
     evt = queue.Dequeue().Single();
     Assert.AreEqual(evt["event.Type"], EventType.Error);
     // event source
     log.Info("");
     evt = queue.Dequeue().Single();
     Assert.AreEqual(evt["Event.Source"], GetType());
     new Log(typeof(String)).Info("");
     evt = queue.Dequeue().Single();
     Assert.AreEqual(evt["Event.Source"], typeof(String));
     // event timestamp
     Int64 oldStamp = 0;
     log.Info("");
     evt = queue.Dequeue().Single();
     oldStamp = (Int64)evt["Event.Timestamp"];
     Assert.IsTrue(oldStamp != 0);
     log.Info("");
     evt = queue.Dequeue().Single();
     Assert.IsTrue((Int64)evt["Event.Timestamp"] > oldStamp);
     // event time
     DateTime oldTime;
     log.Info("");
     evt = queue.Dequeue().Single();
     oldTime = (DateTime)evt["Event.Time"];
     Assert.IsTrue(oldTime > DateTime.UtcNow - TimeSpan.FromMinutes(1));
     Assert.IsTrue(oldTime <= DateTime.UtcNow);
     log.Info("");
     evt = queue.Dequeue().Single();
     Assert.IsTrue((DateTime)evt["Event.Time"] >= oldTime);
     // event message
     log.Info(null);
     evt = queue.Dequeue().Single();
     Assert.IsNull(evt["Event.Message"]);
     log.Info("");
     evt = queue.Dequeue().Single();
     Assert.AreEqual(evt["Event.Message"], "");
     log.Info(" ");
     evt = queue.Dequeue().Single();
     Assert.AreEqual(evt["Event.Message"], " ");
     log.Info("test");
     evt = queue.Dequeue().Single();
     Assert.AreEqual(evt["Event.Message"], "test");
     log.Info("test{0}test{1}test", 0, 1);
     evt = queue.Dequeue().Single();
     Assert.AreEqual(evt["Event.Message"], "test0test1test");
     // event exception
     log.Trace(null);
     evt = queue.Dequeue().Single();
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:NLogEx,代码行数:101,代码来源:TestLog.cs

示例3: TestUnlogged

 public void TestUnlogged()
 {
     var log = new Log(this);
      log.Event(EventType.Trace, "event");
      log.Event(EventType.Info, "{0}", "test");
      log.Event(EventType.Warning, new Exception("test"));
      log.Event(EventType.Error, new Exception("test"), "test");
      log.Event(EventType.Trace, new Exception("test"), "{0}", "test");
      log.EventEx(EventType.Info, new { Value = "test" });
      log.EventEx(EventType.Warning, new { Value = "test" }, "test");
      log.EventEx(EventType.Error, new { Value = "test" }, "{0}", new[] { "test" });
      log.EventEx(EventType.Info, new { Value = "test" }, new Exception("test"));
      log.EventEx(EventType.Warning, new { Value = "test" }, new Exception("test"), "test");
      log.EventEx(EventType.Error, new { Value = "test" }, new Exception("test"), "{0}", "test");
      log.Trace("trace");
      log.TraceEx("{0}", "test");
      log.TraceEx(new { Value = "test" });
      log.TraceEx(new { Value = "test" }, "test");
      log.TraceEx(new { Value = "test" }, "{0}", new[] { "test" });
      log.Info("info");
      log.InfoEx("{0}", "test");
      log.InfoEx(new { Value = "test" });
      log.InfoEx(new { Value = "test" }, "test");
      log.InfoEx(new { Value = "test" }, "{0}", new[] { "test" });
      log.Warn("warning");
      log.Warn("{0}", "test");
      log.Warn(new Exception("test"));
      log.Warn(new Exception("test"), "test");
      log.Warn(new Exception("test"), "{0}", "test");
      log.WarnEx(new { Value = "test" });
      log.WarnEx(new { Value = "test" }, "test");
      log.WarnEx(new { Value = "test" }, "{0}", new[] { "test" });
      log.WarnEx(new { Value = "test" }, new Exception("test"));
      log.WarnEx(new { Value = "test" }, new Exception("test"), "test");
      log.WarnEx(new { Value = "test" }, new Exception("test"), "{0}", "test");
      log.Error("error");
      log.Error("{0}", "test");
      log.Error(new Exception("test"));
      log.Error(new Exception("test"), "test");
      log.Error(new Exception("test"), "{0}", "test");
      log.ErrorEx(new { Value = "test" });
      log.ErrorEx(new { Value = "test" }, "test");
      log.ErrorEx(new { Value = "test" }, "{0}", new[] { "test" });
      log.ErrorEx(new { Value = "test" }, new Exception("test"));
      log.ErrorEx(new { Value = "test" }, new Exception("test"), "test");
      log.ErrorEx(new { Value = "test" }, new Exception("test"), "{0}", "test");
 }
开发者ID:modulexcite,项目名称:NLogEx,代码行数:47,代码来源:TestLog.cs


注:本文中的Log.Trace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。