public void SnTrace_DynamicCategories() { // Test initialization CleanupAndEnableAll(); // Activate Custom and Test categories. Any other be inactive. SnTrace.DisableAll(); SnTrace.Custom.Enabled = true; SnTrace.Test.Enabled = true; // Write 7 lines including dynamic categories SnTrace.Write("Line1"); SnTrace.Category("asdf").Write("Line2"); SnTrace.Test.Write("Line3"); SnTrace.Category("qwer").Write("Line4"); SnTrace.Test.Write("Line5"); SnTrace.Category("yxcv").Write("Line6"); SnTrace.Write("Line7"); // Get log var log = DisableAllAndGetLog(); // Get categories var categories = log .Select(Entry.Parse) .Where(e => e != null) .Select(e => e.Category) .ToArray(); var actual = string.Join(",", categories); // Verify Assert.AreEqual("Custom,asdf,Test,qwer,Test,yxcv,Custom", actual); }
public void SnTrace_DynamicCategoryOnOff() { // Test initialization CleanupAndEnableAll(); // Activate Custom and Test categories. Any other be inactive. SnTrace.DisableAll(); SnTrace.Custom.Enabled = true; SnTrace.Test.Enabled = true; // Pin custom categories var asdf = SnTrace.Category("asdf"); var qwer = SnTrace.Category("qwer"); var yxcv = SnTrace.Category("yxcv"); asdf.Write("0"); qwer.Write("1"); yxcv.Write("2"); asdf.Enabled = false; asdf.Write("3"); qwer.Write("4"); yxcv.Write("5"); yxcv.Enabled = false; asdf.Write("6"); qwer.Write("7"); yxcv.Write("8"); asdf.Enabled = true; yxcv.Enabled = true; qwer.Enabled = false; asdf.Write("9"); qwer.Write("A"); yxcv.Write("B"); qwer.Enabled = true; asdf.Write("C"); qwer.Write("D"); yxcv.Write("E"); // Get log var log = DisableAllAndGetLog(); // Get categories var categories = log .Select(Entry.Parse) .Where(e => e != null) .Select(e => e.Message) .ToArray(); var actual = string.Join("", categories); // Verify Assert.AreEqual("0124579BCDE", actual); }
/// <summary> /// Enables trace categories. It only switches the provided categories ON, /// it does not switch off the ones that are not listed. /// </summary> internal static void UpdateCategories(string[] categoryNames) { if (categoryNames == null) { SnTrace.DisableAll(); return; } // do not switch off any category, only switch ON the listed ones foreach (var category in SnTrace.Categories.Where(c => categoryNames.Contains(c.Name))) { category.Enabled = true; } SnTrace.System.Write("Trace settings were updated. Enabled: {0}", string.Join(", ", SnTrace.Categories .Where(c => c.Enabled).Select(c => c.Name))); }
protected List <string> DisableAllAndGetLog() { SnTrace.Flush(); SnTrace.DisableAll(); return(GetLog()); }