//----------------------------------------------------------------------------------------------------------------------------------------------------- public void ThreadStarted(ThreadLog threadLog) { lock ( _syncRoot ) { _runningThreads.Add(threadLog); } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public void ThreadFinished(ThreadLog threadLog) { lock ( _syncRoot ) { _runningThreads.Remove(threadLog); } PersistLogInXmlFormat(threadLog); }
public void SetUp() { Framework.NodeConfiguration.ApplicationName = "A1"; Framework.NodeConfiguration.NodeName = "N1"; Framework.NodeConfiguration.InstanceId = "I1"; Framework.NodeConfiguration.EnvironmentName = "E1"; Framework.PresetUtcNow = new DateTime(2015, 1, 30, 15, 22, 54, 345); _rootActivity = new FormattedActivityLogNode("root"); Framework.PresetGuids.Enqueue(new Guid(TestLogId)); _threadLog = new ThreadLog(Framework, Clock, Registry, Anchor, ThreadTaskType.Unspecified, _rootActivity); }
public void GenerateExampleThreadLogs(ThreadTaskType taskType, string rootActivityText, bool includeWarning, bool includeError) { var realThreadRegistry = new ThreadRegistry(@"D:\ThreadLogExamples"); var rootActivity = new FormattedActivityLogNode(rootActivityText); var log = new ThreadLog(Framework, _clock, realThreadRegistry, taskType, rootActivity); log.AppendNode(new FormattedLogNode(LogLevel.Info, "One")); log.AppendNode(new FormattedActivityLogNode("Two")); log.AppendNode(new FormattedLogNode(LogLevel.Verbose, "Two-1")); log.AppendNode(new FormattedLogNode(LogLevel.Verbose, "Two-2")); log.AppendNode(new FormattedLogNode(LogLevel.Info, "Three")); log.AppendNode(new FormattedActivityLogNode("Four")); if ( includeError ) { try { throw new Exception("This is a generated exception"); } catch ( Exception e ) { log.AppendNode(new FormattedLogNode(LogLevel.Error, "Five", exception: e, fullDetailsText: e.ToString())); } } log.CurrentActivity.Close(); if ( includeWarning ) { log.AppendNode(new FormattedLogNode(LogLevel.Warning, "Six")); } log.AppendNode(new FormattedLogNode(LogLevel.Debug, "Two-3")); log.AppendNode(new FormattedLogNode(LogLevel.Debug, "Two-4")); Thread.Sleep(5000); }
public void NewInstance_TaskType_AsSpecified() { //-- Act var log = new ThreadLog( Framework, Clock, Registry, Anchor, ThreadTaskType.QueuedWorkItem, new FormattedActivityLogNode("Test")); //-- Assert Assert.That(log.TaskType, Is.EqualTo(ThreadTaskType.QueuedWorkItem)); }
public void NewInstance_StartedAtUtc_EqualsUtcNow() { //-- Arrange var now = new DateTime(2014, 10, 15, 12, 30, 45); Framework.UtcNow = now; //-- Act var log = new ThreadLog( Framework, Clock, Registry, Anchor, ThreadTaskType.Unspecified, new FormattedActivityLogNode("Test")); //-- Assert Assert.That(log.ThreadStartedAtUtc, Is.EqualTo(now)); }
public void NewInstance_LogId_IsNewGuid() { //-- Arrange var newGuid = new Guid("E690328B-994E-494F-B4F6-B317A0E2668B"); Framework.PresetGuids.Enqueue(newGuid); //-- Act var log = new ThreadLog( Framework, Clock, Registry, Anchor, ThreadTaskType.Unspecified, new FormattedActivityLogNode("Test")); //-- Assert Assert.That(log.LogId, Is.EqualTo(newGuid)); }
public void NewInstance_CurrentActivity_IsRootActivity() { //-- Arrange var rootActivity = new FormattedActivityLogNode("Root"); //-- Act var log = new ThreadLog( Framework, Clock, Registry, Anchor, ThreadTaskType.Unspecified, rootActivity); //-- Assert Assert.That(log.RootActivity, Is.SameAs(rootActivity)); Assert.That(log.CurrentActivity, Is.SameAs(rootActivity)); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private void PersistLogInXmlFormat(ThreadLog log) { var serializer = new DataContractSerializer(typeof(ThreadLogSnapshot)); var fileName = log.LogId.ToString("N") + ".threadlog"; using ( var file = File.Create(Path.Combine(_threadLogFolder, fileName)) ) { var writer = XmlWriter.Create(file); serializer.WriteObject(writer, log.TakeSnapshot()); writer.Flush(); } }
//------------------------------------------------------------------------------------------------------------------------------------------------- public void ThreadStarted(ThreadLog threadLog) { _runningThreads.Add(threadLog); }
//------------------------------------------------------------------------------------------------------------------------------------------------- public void ThreadFinished(ThreadLog threadLog) { _runningThreads.Remove(threadLog); }