本文整理汇总了C#中Log.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Log.Add方法的具体用法?C# Log.Add怎么用?C# Log.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Log
的用法示例。
在下文中一共展示了Log.Add方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: when_a_cluster_has_nodes_that_crash_very_often_then_logs_are_still_persisted
public async Task when_a_cluster_has_nodes_that_crash_very_often_then_logs_are_still_persisted()
{
Subject<IEnumerable<Peer>> peerObservable = new Subject<IEnumerable<Peer>>();
var scheduler = new VirtualScheduler();
var cluster = TestNode.CreateCluster(clusterSize: 20, peerObservable: peerObservable, scheduler: scheduler);
cluster.Start();
await cluster.WaitForLeader(scheduler);
var expectedServerLog = new Log();
var crasher = cluster.ToArray().StartRandomlyCrashing(peerObservable, new Random(), scheduler);
var validator = Observable.Interval(TimeSpan.FromSeconds(1), scheduler)
.Subscribe(async o =>
{
Validate(cluster);
});
Enumerable.Range(1, 100).ForEach(async i =>
{
var leader = cluster.Leader();
if (leader != null)
{
await leader.AddLog(i.ToString());
expectedServerLog.Add(leader.Term, i.ToString());
}
scheduler.AdvanceBy(TimeSpan.FromSeconds(1));
});
await cluster.WaitForLeader(scheduler);
cluster.Leader().ServerLog.Entries.ShouldBeEquivalentTo(expectedServerLog.Entries);
}
示例2: Add_given_FormatAndArgs_should_AddItem
public void Add_given_FormatAndArgs_should_AddItem()
{
// # Arrange.
ILog sut = new Log();
Assert.IsFalse(sut.Logs.Any(), "There should be no log when we start.");
// # Act.
sut.Add("a{0}c{1}", "b", "d");
// # Assert.
Assert.AreEqual("abcd", sut.Logs.Single());
}
示例3: Add_given_XDocument_should_AddIt
public void Add_given_XDocument_should_AddIt()
{
// # Arrange.
ILog sut = new Log();
Assert.IsFalse(sut.Logs.Any(), "There should be no log when we start.");
var xml = new XDocument();
// # Act.
sut.Add(xml);
// # Assert.
Assert.AreEqual(1, sut.Logs.Count(),
"Right now we don't test the formatting, only the existence of the row.");
}
示例4: Add_given_LogRows_should_AddThem
public void Add_given_LogRows_should_AddThem()
{
// # Arrange.
ILog sut = new Log();
Assert.IsFalse(sut.Logs.Any(), "There should be no log when we start.");
const string RowOne = "My first row";
const string RowTwo = "My second row";
// # Act.
sut.Add(new[] { RowOne, RowTwo });
// # Assert.
Assert.AreEqual(2, sut.Logs.Count());
Assert.AreEqual(RowOne, sut.Logs[0]);
Assert.AreEqual(RowTwo, sut.Logs[1]);
}
示例5: logs_can_be_deterministicly_written_to_a_leader
public async Task logs_can_be_deterministicly_written_to_a_leader()
{
var scheduler = Scheduler.Default;
var cluster = TestNode.CreateCluster(clusterSize: 2, scheduler: scheduler);
cluster.Start();
await cluster.WaitForLeader();
var expectedServerLog = new Log();
Enumerable.Range(1,100).ForEach(async i =>
{
await cluster.Leader().AddLog(i.ToString());
expectedServerLog.Add(cluster.Leader().Term, i.ToString());
});
cluster.Leader().LocalLog.ShouldBeEquivalentTo(expectedServerLog);
cluster.Leader().ServerLog.ShouldBeEquivalentTo(expectedServerLog);
}
示例6: logs_can_be_quickly_written_in_parallel_to_a_leader
public async Task logs_can_be_quickly_written_in_parallel_to_a_leader()
{
var scheduler = Scheduler.Default;
var cluster = TestNode.CreateCluster(clusterSize: 4, scheduler: scheduler);
cluster.Start();
await cluster.WaitForLeader();
var expectedServerLog = new Log();
var result = Enumerable.Range(1, 100).ParrallelForEach( i =>
{
cluster.Leader().AddLog(i.ToString()).Wait();
expectedServerLog.Add(2, i.ToString());
});
cluster.Leader().LocalLog.Entries.Count.Should().Be(101);
cluster.Leader().ServerLog.Entries.Count.Should().Be(101);
cluster.Followers().ForEach(f =>
{
Enumerable.Range(1, 100).ForEach(i =>
{
var s = i.ToString();
f.LocalLog.Entries.Select(e => e.Log).Should().Contain(s);
});
});
}
示例7: clusters_remain_in_a_valid_state_throughout_logging
public async Task clusters_remain_in_a_valid_state_throughout_logging()
{
var scheduler = new VirtualScheduler();
var cluster = TestNode.CreateCluster(clusterSize: 2, scheduler: scheduler);
cluster.Start();
await cluster.WaitForLeader(scheduler);
var expectedServerLog = new Log();
var validationCounter = 0;
Observable.Interval(TimeSpan.FromSeconds(1), scheduler)
.Subscribe(async o =>
{
Validate(cluster);
validationCounter ++;
});
Enumerable.Range(1, 100).ForEach(async i =>
{
await cluster.Leader().AddLog(i.ToString());
expectedServerLog.Add(cluster.Leader().Term, i.ToString());
scheduler.AdvanceBy(TimeSpan.FromSeconds(1));
});
Console.WriteLine("Validation ran {0} times on cluster", validationCounter);
}
示例8: logs_can_be_quickly_written_in_parallel_to_a_leader_with_test_scheduler
public async Task logs_can_be_quickly_written_in_parallel_to_a_leader_with_test_scheduler()
{
var scheduler = new VirtualScheduler();
var cluster = TestNode.CreateCluster(clusterSize: 4, scheduler: scheduler);
cluster.Start();
await cluster.WaitForLeader(scheduler);
var expectedServerLog = new Log();
Enumerable.Range(1, 100).ForEach( i =>
{
cluster.Leader().AddLog(i.ToString()).Wait();
expectedServerLog.Add(cluster.Leader().Term, i.ToString());
scheduler.AdvanceBy(TimeSpan.FromSeconds(1));
});
cluster.Leader().LocalLog.Entries.Count.Should().Be(101);
cluster.Leader().ServerLog.Entries.Count.Should().Be(101);
cluster.Followers().ForEach(f =>
{
Enumerable.Range(1, 100).ForEach(i =>
{
var s = i.ToString();
f.LocalLog.Entries.Select(e => e.Log).Should().Contain(s);
});
});
}
示例9: AddDebugInfoData
/// <summary>
/// Adds debug information data to information list.
/// </summary>
/// <param name="info">The information list.</param>
/// <param name="complete">If set to <c>true</c> add complete information.</param>
private void AddDebugInfoData(Log.InfoList info, bool complete)
{
if (complete)
{
info.Add("VehicleId", this.vehicleId);
Vehicle vehicle = Singleton<VehicleManager>.instance.m_vehicles.m_buffer[this.vehicleId];
info.Add("LeadingVehicle", vehicle.m_leadingVehicle);
info.Add("TrailingVehicle", vehicle.m_trailingVehicle);
info.Add("Spawned", vehicle.m_flags & Vehicle.Flags.Spawned);
info.Add("Flags", vehicle.m_flags);
info.Add("Info", vehicle.Info);
if (vehicle.Info != null)
{
info.Add("IsLargeVehicle", vehicle.Info.m_isLargeVehicle);
}
}
if (this.isStuck || this.isBroken)
{
info.Add("Problem", this.isStuck ? "Stuck" : null, this.isBroken ? "Broken" : null);
}
if (this.confusedSinceFrame > 0 || this.confusedSinceTime > 0)
{
info.Add("Confused", this.ConfusedForSeconds, this.ConfusedForFrames);
}
if (this.checkFlagSinceFrame > 0 || this.checkFlagSinceTime > 0)
{
info.Add("Flagged", this.checkFlags, this.CheckFlaggedForSeconds, this.CheckFlaggedForFrames);
}
}
示例10: TestPartialLog
public void TestPartialLog()
{
Log partialLog = new Log(new[]
{
new KeyValuePair<string, string>(Log.GuidKey, CombGuid.NewCombGuid().ToString()),
new KeyValuePair<string, string>(Log.LevelKey, LoggingLevel.SystemNotification.ToString()),
new KeyValuePair<string, string>(Log.ThreadIDKey, "1"),
new KeyValuePair<string, string>(Log.ExceptionTypeFullNameKey, "System.Data.SqlException"),
new KeyValuePair<string, string>(Log.StoredProcedureKey, "spTest"),
new KeyValuePair<string, string>(Log.StoredProcedureLineKey, "2")
});
Assert.IsNotNull(partialLog);
partialLog.Add();
}
示例11: TestPartialLogMinimum
public void TestPartialLogMinimum()
{
var loggers = Log.Loggers.ToArray();
foreach (var logger in loggers)
Log.RemoveLogger(logger);
Log.SetTrace();
Log.Flush();
Log partialLog = new Log(new[]
{
new KeyValuePair<string, string>(Log.GuidKey, CombGuid.NewCombGuid().ToString())
});
Assert.IsNotNull(partialLog);
partialLog.Add();
}