public IEnumerable <ErrorDisplay> SelectErrors(LogQuery query) { Contract.Requires <ArgumentNullException>(null != query); Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != query.ApplicationIdentifier, "Application Identifier is empty."); Contract.Ensures(Contract.Result <IEnumerable <ErrorDisplay> >() != null); using (new PerformanceMonitor()) { query.Initialize(); var start = query.From.Value; var end = query.To.Value; var list = new List <ErrorDisplay>(); if (query.IsUnique) { var item = this.errorTable.Get <ErrorDisplay, ErrorData>(query.PartitionKey, query.RowKey); if (null != item) { list.Add(item); } return(list); } else if (start < DateTime.UtcNow.AddHours(-6)) { var history = this.Get <ErrorDisplay>(Error21DaysFormat.FormatWithCulture(query.PartitionKey)); if (null != history) { list.AddRange(history.Items); start = history.MaximumDate.HasValue ? history.MaximumDate.Value : start; } } if (start < end) { using (var perf = new PerformanceMonitor()) { perf.Append("Pulling from table storage."); var results = this.errorTable.Query <ErrorData>(query); var temp = results.AsParallel().ToList().Select(d => d.Convert()); perf.Append("{0} pulled from table.", temp.Count()); list.AddRange(temp); } } var items = query.Filter <ErrorDisplay>(list); if (query.Deep.HasValue && !query.Deep.Value && 1 < items.Count()) { foreach (var error in items) { error.StackTrace = null; } } return(items); } }
public void DurationTooSmall() { var message = Guid.NewGuid().ToString(); using (var perf = new PerformanceMonitor()) { Assert.IsNull(perf.Content, "Content should be null"); perf.Append(message); Assert.AreEqual <string>(message, perf.Content, "Message should match"); } var source = new Abc.Services.Core.LogCore(); var query = new Abc.Services.Contracts.LogQuery() { ApplicationIdentifier = Application.Identifier, }; var items = source.SelectOccurrences(query); foreach (var item in items) { if (item.Message == message) { Assert.Fail("Perf occurance was saved."); } } }
/// <summary> /// Get Object from Blob /// </summary> /// <typeparam name="T">Log Item</typeparam> /// <param name="objectId">Object Identifier</param> /// <returns>Log History</returns> private LogHistory <T> Get <T>(string objectId) where T : LogItem { using (var perf = new PerformanceMonitor()) { perf.Append("Pulling from blob storage."); var blob = new BinaryBlob <LogHistory <T> >(ServerConfiguration.Default); return(blob.GetDigest <LogHistory <T> >(objectId)); } }
public void AppendStringFormatComment() { var comment = "this is my comment"; using (var perf = new PerformanceMonitor()) { Assert.IsNull(perf.Content, "Content should be null"); perf.Append("{0}:{0}", comment); Assert.AreEqual <string>(comment + ':' + comment, perf.Content); } }
public void AppendComment() { string comment = "this is my comment"; using (PerformanceMonitor perf = new PerformanceMonitor()) { Assert.IsNull(perf.Content, "Content should be null"); perf.Append(comment); Assert.AreEqual <string>(comment, perf.Content); } }
public void AppendStringFormatComment() { using (PerformanceMonitor perf = new PerformanceMonitor()) { string comment = "this is my comment"; Assert.IsNull(perf.Content, "Content should be null"); perf.Append("{0}:{0}", comment); Assert.AreEqual <string>(comment + ':' + comment, perf.Content); Thread.Sleep(5); Assert.IsTrue(0 < perf.Duration.Ticks, "Duration In Ticks should be set"); } }
public void LogOccurrence() { var message = Guid.NewGuid().ToString(); using (var perf = new PerformanceMonitor()) { Assert.IsNull(perf.Content, "Content should be null"); Thread.Sleep(perf.MinimumDuration.Add(new TimeSpan(0, 0, 2))); perf.Append(message); } var source = new Abc.Services.Core.LogCore(); var query = new Abc.Services.Contracts.LogQuery() { ApplicationIdentifier = Settings.ApplicationIdentifier, From = DateTime.UtcNow.AddMinutes(-5), }; int i = 0; Abc.Services.Contracts.OccurrenceDisplay occurance = null; while (occurance == null && i < 50) { Thread.Sleep(100); occurance = (from data in source.SelectOccurrences(query) where message == data.Message select data).FirstOrDefault(); i++; } Assert.IsNotNull(occurance, "Occurrence should not be null"); Assert.AreEqual <Guid>(Application.Identifier, occurance.Token.ApplicationId, "Application Id should match"); Assert.AreEqual <string>(Environment.MachineName, occurance.MachineName, "Machine Name should match"); Assert.AreEqual <string>(message, occurance.Message, "Message should match"); Assert.AreEqual <string>("Void LogOccurrence()", occurance.Method, "Method should match"); Assert.AreEqual <string>(this.GetType().ToString(), occurance.Class, "Type should match"); Assert.AreEqual <int>(Thread.CurrentThread.ManagedThreadId, occurance.ThreadId, "Thread Id should match"); }