public void EventHandling() { LogsCollection logsCollection = new LogsCollection(); bool isCalled = false; logsCollection.OnAdd += (entry) => { isCalled = !isCalled; }; logsCollection.Add(new Entry("smth")); Assert.IsTrue(isCalled); logsCollection.Add(new Entry("smth2")); Assert.IsFalse(isCalled); logsCollection.Add(new Entry("smth3")); Assert.IsTrue(isCalled); LogsCollection logsCollection2 = new LogsCollection(); logsCollection.OnAdd += (entry) => { logsCollection2.Add(new Entry(entry.Text, entry.Time, entry.Level)); }; logsCollection.Add(new Entry ( "test2.0", new DateTime(1992, 6, 12, 12, 0, 0), EntryLevel.System) ); Entry expected = new Entry("test2.0", new DateTime(1992, 6, 12, 12, 0, 0), EntryLevel.System); Assert.AreEqual(expected, logsCollection2.LastAdded()); }
public void RemoveTest() { // Log BigWatson.Instance.ResetAsync().Wait(); foreach (Exception exception in new Exception[] { new InvalidOperationException("Hello world!"), new ArgumentException("This parameter was too weird to be evaluated") }) { BigWatson.Instance.Log(exception); } BigWatson.Instance.Log(EventPriority.Info, "Some random info"); BigWatson.Instance.Log(EventPriority.Warning, "Watch out!"); // Checks LogsCollection <Event> reports = BigWatson.Instance.LoadEventsAsync().Result; Assert.IsTrue(reports.LogsCount == 2); Assert.IsTrue(reports.Logs.First().Priority == EventPriority.Warning); Assert.IsTrue(reports.Logs.Skip(1).First().Priority == EventPriority.Info); BigWatson.Instance.ResetAsync <Event>().Wait(); Assert.IsTrue(BigWatson.Instance.LoadEventsAsync().Result.LogsCount == 0); BigWatson.Instance.ResetAsync <ExceptionReport>().Wait(); Assert.IsTrue(BigWatson.Instance.LoadExceptionsAsync().Result.LogsCount == 0); }
public void LogPredicateTest() { // Log BigWatson.Instance.ResetAsync().Wait(); Exception[] exceptions = { new InvalidOperationException("Hello world!"), new ArithmeticException("Division by zero"), new InvalidOperationException("We're being too lazy here!"), }; foreach (Exception exception in exceptions) { try { throw exception; } catch (Exception e) { BigWatson.Instance.Log(e); } } // Checks LogsCollection <ExceptionReport> reports = BigWatson.Instance.LoadExceptionsAsync(entry => entry.ExceptionType.Equals(typeof(InvalidOperationException).ToString())).Result; Assert.IsTrue(reports.LogsCount == 2); Assert.IsTrue(reports[0][1].Message.Equals(exceptions[0].Message)); }
public void LogsByEntryLevel() { LogsCollection logsCollection = new LogsCollection(); List <string> results = new List <string> { "ban smwh", "add smth", "delete smth" }; logsCollection.Add(new Entry(results[0], EntryLevel.Admin)); logsCollection.Add(new Entry(results[1], EntryLevel.Admin)); logsCollection.Add(new Entry(results[2], EntryLevel.Admin)); logsCollection.Add(new Entry("try ban", EntryLevel.User)); logsCollection.Add(new Entry("try add", EntryLevel.Undefined)); logsCollection.Add(new Entry("try delete", EntryLevel.Server)); List <Entry> entries = logsCollection.GetLogsByLevel(EntryLevel.Admin).ToList(); Assert.AreEqual(3, entries.Count()); Assert.AreEqual(results[0], entries[0].Text); Assert.AreEqual(EntryLevel.Admin, entries[0].Level); Assert.AreEqual(results[1], entries[1].Text); Assert.AreEqual(EntryLevel.Admin, entries[1].Level); Assert.AreEqual(results[2], entries[2].Text); Assert.AreEqual(EntryLevel.Admin, entries[2].Level); }
public void DatabaseExportTest() { // Log BigWatson.Instance.ResetAsync().Wait(); try { throw new InvalidOperationException("Export test"); } catch (Exception e) { BigWatson.Instance.Log(e); } string path = Path.Combine(LocalPath, $"test{BigWatson.DatabaseExtension}"); BigWatson.Instance.ExportAsync(path).Wait(); // Check IReadOnlyLogger loaded = BigWatson.Load(path); LogsCollection <ExceptionReport> reports = loaded.LoadExceptionsAsync().Result; Assert.IsTrue(reports.LogsCount == 1); Assert.IsTrue(reports.Logs.First().ExceptionType.Equals(typeof(InvalidOperationException).ToString())); Assert.IsTrue(reports.Logs.First().Message.Equals("Export test")); File.Delete(path); }
public CoreLoggerProxy() { //用这种奇葩方法初始化是为了防止线程问题 Task.WaitAll(Task.Run(() => { Logs = new LogsCollection(); })); }
public void LogsCollectionIsCollection() { LogsCollection logsCollection = new LogsCollection(); logsCollection.Add(new Entry("log1")); logsCollection.Add(new Entry("log2", new DateTime(2019, 6, 7, 5, 0, 32))); Assert.AreEqual(2, logsCollection.Count()); }
public override void ViewAppeared() { base.ViewAppeared(); _token ??= _messenger.Subscribe <NotificationMessage>(msg => { LogsCollection.Add(new LogLine($"{DateTime.Now:T}: {msg.Message}", msg.Data)); RaisePropertyChanged(() => LogsCollection); }); }
public HttpResponseMessage Post([FromBody] LogTypeClass logType) { if (logType != null) { LogsCollection.Clear(logType.logType); return(GetSpecificLogEntries(logType.logType)); } else { LogsCollection.Clear(null); return(GetAllLogEntries()); } }
public void LogThresholdTest() { // Log BigWatson.Instance.ResetAsync().Wait(); BigWatson.Instance.Log(EventPriority.Info, "Some random info"); BigWatson.Instance.Log(EventPriority.Warning, "Watch out!"); // Checks LogsCollection <Event> reports = BigWatson.Instance.LoadEventsAsync(TimeSpan.FromDays(2)).Result; Assert.IsTrue(reports.LogsCount == 2); Assert.IsTrue(reports.Logs.First().Priority == EventPriority.Warning); Assert.IsTrue(reports.Logs.Skip(1).First().Priority == EventPriority.Info); }
public void EnumerationCollection() { LogsCollection logsCollection = new LogsCollection(); logsCollection.Add(new Entry("log...")); logsCollection.Add(new Entry("log..")); logsCollection.Add(new Entry("log.")); logsCollection.Add(new Entry("log")); Assert.AreEqual("log...", logsCollection[0].Text); Assert.AreEqual("log..", logsCollection[1].Text); Assert.AreEqual("log.", logsCollection[2].Text); Assert.AreEqual("log", logsCollection[3].Text); }
public void LogsCollectionCountOfContains() { LogsCollection logsCollection = new LogsCollection(); for (int i = 0; i < 10; ++i) { logsCollection.Add(new Entry("log" + i.ToString())); if (i % 2 == 0) { logsCollection.Add(new Entry("Log" + i.ToString() + ".2")); logsCollection.Add(new Entry("lo" + i.ToString() + "g")); } } Assert.AreEqual(20, logsCollection.Count()); Assert.AreEqual(15, logsCollection.CountOfContains("log")); Assert.AreEqual(10, logsCollection.CountOfContains("log", true)); }
public void MemoryParserTest() { // Log BigWatson.Instance.ResetAsync().Wait(); BigWatson.MemoryParser = () => 128L; try { throw new InvalidOperationException(); } catch (Exception e) { BigWatson.Instance.Log(e); } // Checks LogsCollection <ExceptionReport> reports = BigWatson.Instance.LoadExceptionsAsync().Result; Assert.IsTrue(reports.Logs.First().UsedMemory == 128L); }
public void LastLog() { LogsCollection logsCollection = new LogsCollection(); Entry log1 = new Entry("smth", new DateTime(2203, 1, 1, 1, 1, 1)); Entry log2 = new Entry("smth2"); logsCollection.Add(log1); for (int i = 0; i < 10; ++i) { logsCollection.Add(new Entry("smth for " + i.ToString())); } logsCollection.Add(log2); Entry lastLog1 = logsCollection.LastByTime(); Entry lastLog2 = logsCollection.LastAdded(); Assert.AreEqual(log1, lastLog1); Assert.AreEqual(log2, lastLog2); }
public void LogThresholdTest() { // Log BigWatson.Instance.ResetAsync().Wait(); try { throw new InvalidOperationException("Hello world!"); } catch (Exception e) { BigWatson.Instance.Log(e); } // Checks LogsCollection <ExceptionReport> reports = BigWatson.Instance.LoadExceptionsAsync(TimeSpan.FromMinutes(1)).Result; Assert.IsTrue(reports.LogsCount == 1); Assert.IsTrue(reports.Logs.First().ExceptionType.Equals(typeof(InvalidOperationException).ToString())); Assert.IsTrue(reports.Logs.First().Message.Equals("Hello world!")); Assert.IsTrue(DateTime.Now.Subtract(reports.Logs.First().Timestamp) < TimeSpan.FromMinutes(1)); }
public void JsonExportTest() { // Log BigWatson.Instance.ResetAsync().Wait(); Exception[] exceptions = { new InvalidOperationException("Hello world!"), new ArithmeticException("Division by zero"), new NotImplementedException("We're being too lazy here!"), new ArgumentException("This parameter was too weird to be evaluated") }; foreach (Exception exception in exceptions) { try { throw exception; } catch (Exception e) { BigWatson.Instance.Log(e); } } BigWatson.Instance.Log(EventPriority.Info, "Some random info"); BigWatson.Instance.Log(EventPriority.Warning, "Watch out!"); // Checks LogsCollection <ExceptionReport> reports = BigWatson.Instance.LoadExceptionsAsync().Result; Assert.IsTrue(reports.LogsCount == exceptions.Length); string json = BigWatson.Instance.ExportAsJsonAsync().Result; Assert.IsTrue(json.Length > 0); foreach (Exception exception in exceptions) { Assert.IsTrue(json.Contains(exception.GetType().Name)); Assert.IsTrue(json.Contains(exception.Message)); } Assert.IsTrue(json.Contains(EventPriority.Info.ToString())); Assert.IsTrue(json.Contains(EventPriority.Warning.ToString())); }
public LogsCollection GetActionLogByReffID(string InternalID) { LogsCollection logss = null; if (!this.IsReady) { base.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn); if (this.IsReady = base.CurDBEngine.Connect()) { this.CurSQLFactory = new SQLFactory(this.DBType); } } if (this.IsReady) { DatabaseParameters parameters = new DatabaseParameters(); parameters.Add(new DatabaseParameter(this.DataStructure.Tables.LogActions.ReffID.ActualFieldName, InternalID)); this.CurSQLFactory.SelectCommand(parameters, this.DataStructure.Tables.LogActions.ActualTableName); DataTable table = base.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL); if (table != null) { logss = new LogsCollection(); DataRow[] rowArray = table.Select("", this.DataStructure.Tables.LogActions.LogDateTime.ActualFieldName); foreach (DataRow row in rowArray) { ActionLogItem item = new ActionLogItem { ReffID = row[this.DataStructure.Tables.LogActions.ReffID.ActualFieldName].ToString(), LogDate = Convert.ToDateTime(row[this.DataStructure.Tables.LogActions.LogDateTime.ActualFieldName]), LoggedBy = new ApplicationUser(row[this.DataStructure.Tables.LogActions.LogBy.ActualFieldName].ToString()), ActionDescription = row[this.DataStructure.Tables.LogActions.Description.ActualFieldName].ToString() }; logss.Add(item); } return(logss); } this.ErrMsg = "[LogManager.GetActionLogByReffID] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + base.CurDBEngine.ErrorMessage; } return(logss); }
public Logger() { Logs = new LogsCollection(); }