public UseCaseTests() { Bilge.AddHandler(new TCPHandler("127.0.0.1", 9060), HandlerAddOptions.SingleType); Bilge.SetConfigurationResolver((nm, lvl) => { return(System.Diagnostics.SourceLevels.Verbose); }); }
public UseCaseTests() { Bilge.AddMessageHandler(new TCPHandler("127.0.0.1", 9060)); Bilge.SetConfigurationResolver((a, b) => { return(System.Diagnostics.SourceLevels.Verbose); }); }
public void Resolver_OverwritesConstructor() { try { Bilge.SetConfigurationResolver((nm, def) => { return(SourceLevels.Verbose); }); Bilge b = new Bilge(); Assert.Equal(SourceLevels.Verbose, b.ActiveTraceLevel); } finally { Bilge.ClearConfigurationResolver(); } }
public void Resolver_GetsName() { try { const string INAME = "InstanceName"; Bilge.SetConfigurationResolver((nm, def) => { Assert.Equal(INAME, nm); return(SourceLevels.Off); }); Bilge b = new Bilge(INAME); } finally { Bilge.ClearConfigurationResolver(); } }
public void Resolver_GetsInitialValue() { try { const string INAME = "InstanceName"; Bilge.SetConfigurationResolver((nm, def) => { Assert.Equal <SourceLevels>(SourceLevels.Critical, def); return(SourceLevels.Off); }); Bilge b = new Bilge(INAME, tl: SourceLevels.Critical); } finally { Bilge.ClearConfigurationResolver(); } }
private static void Main(string[] args) { #if DEBUG Bilge.AddHandler(new TCPHandler("127.0.0.1", 9060)); Bilge.SetConfigurationResolver((nm, inval) => { return(System.Diagnostics.SourceLevels.Verbose); }); #endif var b = new Bilge(); Bilge.Alert.Online("ticktocktalkie"); try { string timeStr = DateTime.Now.Hour + ":" + DateTime.Now.Minute; if (args.Length != 0) { b.Verbose.Log("Time override from command line", args[0]); timeStr = args[0]; } string response; try { IConvertTime ict = ConverterChainBase.GetFullChain(); var tsc = new TalkingClockSupport(ict); var st = tsc.ParseTime(timeStr); response = tsc.ConvertTime(new SmallTimeRenderer(st)); } catch (ArgumentOutOfRangeException) { response = "Invalid time format, please try HH:MM"; } b.Verbose.Log($"Response [{response}]"); Console.WriteLine(response); } catch (Exception ex) { b.Error.Dump(ex, "Unknown Fault"); throw; } }
private static void Main(string[] args) { Console.WriteLine("Plisky Tool - Online."); var clas = new CommandArgumentSupport(); clas.ArgumentPostfix = "="; clas.ProcessArguments(options, args); if (!ValidateArgumentSettings(options)) { // TODO : Merge this in with the same code below Console.WriteLine("Fatal: Argument Validation Failed."); Console.WriteLine(); string s = clas.GenerateShortHelp(options, "Plisky Tool"); Console.WriteLine(s); return; } if ((options.Debug) || (!string.IsNullOrEmpty(options.Trace))) { Console.WriteLine("Debug Mode, Adding Trace Handler"); Bilge.AddHandler(new ConsoleHandler(), HandlerAddOptions.SingleType); Bilge.SetConfigurationResolver((name, inLevel) => { SourceLevels returnLvl = SourceLevels.Verbose; if ((options.Trace != null) && (options.Trace.ToLowerInvariant() == "info")) { returnLvl = SourceLevels.Information; } if ((name.Contains("Plisky-Versioning")) || (name.Contains("Plisky-Tool"))) { return(returnLvl); } return(inLevel); }); } Bilge b = new Bilge("Plisky-Tool"); Bilge.Alert.Online("Plisky-Tool"); b.Verbose.Dump(options, "App Options"); if (PerformActionsFromCommandline()) { if (versionerUsed != null) { VersioningOutputter vo = new VersioningOutputter(versionerUsed); vo.DoOutput(options.OutputsActive); } b.Info.Log("All Actions - Complete - Exiting."); } else { // TODO : Merge this in with the same code Above string s = clas.GenerateShortHelp(options, "Plisky Tool"); Console.WriteLine(s); } b.Verbose.Log("Plisky Tool - Exit."); b.Flush(); }
private static void Main(string[] args) { string dt = $"{DateTime.Now.Hour}{DateTime.Now.Minute}{DateTime.Now.Second}"; FileSystemHandler fsh = new FileSystemHandler(new FSHandlerOptions("c:\\Temp\\votalot\\dummy" + dt + ".log")); fsh.SetFormatter(new FlimFlamV2Formatter()); Bilge.AddMessageHandler(new ConsoleHandler()); Bilge.AddMessageHandler(new TCPHandler("127.0.0.1", 9060)); Bilge.AddMessageHandler(fsh); Bilge.Alert.Online("TestClient"); #if CORE // Due to the dependency on configurations and the different ways that you can configure a core service this is not // implemented within Bilge even as a default but is documented instead. Bilge.SetConfigurationResolver((s, lvl) => { var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", false, true) .Build(); SourceLevels result = lvl; string defaultValue = configuration["logging:loglevel:default"]; string specificForThisInstance = configuration[$"logging:loglevel:{s}"]; if (Enum.TryParse <SourceLevels>(specificForThisInstance, out SourceLevels slSpecific)) { result = slSpecific; } else { if (Enum.TryParse <SourceLevels>(defaultValue, out SourceLevels slDefault)) { result = slDefault; } } return(result); }); #else Bilge.SetConfigurationResolver((instanceName, lvl) => { // Logic -> Try Source Switch, Failing that Trace Switch, failing that SourceSwitch + Switch, Failing that TraceSwitch+Switch. SourceLevels result = lvl; bool tryTraceSwitches = true; try { SourceSwitch ss = new SourceSwitch(instanceName); if (ss.Level == SourceLevels.Off) { ss = new SourceSwitch($"{instanceName}Switch"); if (ss.Level == SourceLevels.Off) { } else { tryTraceSwitches = false; result = ss.Level; } } else { tryTraceSwitches = false; result = ss.Level; } } catch (SystemException) { // This is the higher level exception of a ConfigurationErrorsException but that one requires a separate reference // This occurs when a TraceSwitch has the same name as the source switch with a value that is not supported by source switch e.g. Info } if (tryTraceSwitches) { TraceSwitch ts = new TraceSwitch(instanceName, ""); if (ts.Level == TraceLevel.Off) { ts = new TraceSwitch($"{instanceName}Switch", ""); if (ts.Level != TraceLevel.Off) { result = Bilge.ConvertTraceLevel(ts.Level); } } else { result = Bilge.ConvertTraceLevel(ts.Level); } } return(result); }); #endif Bilge b = new Bilge("PliskyConsoleTestApp"); b.ActiveTraceLevel = SourceLevels.Verbose; b.Verbose.Log("Hello Cruel World"); bool traceSwitchTests = false; bool bulkFileWriteTests = false; bool perfTests = false; bool basicWriteAllTest = true; bool actionTest = true; if (actionTest) { int acCount = 0; b.Action.RegisterHandler((m) => { if (m.Success) { acCount++; } }, "bob"); b.Action.Occured("Event", "Data"); if (acCount == 0) { throw new InvalidOperationException("didnt work"); } } if (basicWriteAllTest) { Bilge.SetConfigurationResolver((instanceName, lvl) => { return(SourceLevels.Verbose); }); ModularWriting mw = new ModularWriting(); mw.DoWrite(); } if (bulkFileWriteTests) { ProductionLoggingTest(b); } b.Flush(); if (perfTests) { PerformanceTest p = new PerformanceTest(); p.AnalysisBatchVsNoBatch(); //p.ExecuteTest(); p.WriteOutput(); Bilge.ForceFlush(); } Console.ReadLine(); return; b.AddHandler(new SimpleTraceFileHandler(@"c:\temp\")); if (traceSwitchTests) { Console.WriteLine("Actual Trace Level : " + b.ActiveTraceLevel.ToString()); try { TraceSource ts = new TraceSource("monkeySwitch", SourceLevels.Off); TraceSwitch tx = new TraceSwitch("monkey2Switch", "test", "Off"); SourceSwitch sw = new SourceSwitch("boner", "off"); Console.WriteLine($"{ts.Switch.Level} >> {tx.Level} >> {sw.Level}"); Console.ReadLine(); } catch (Exception ex) { } } bool doDirectWriting = false; if (args.Length > 0) { if (args[0] == "direct") { doDirectWriting = true; } } if (doDirectWriting) { var dr = new DirectWriting(b); dr.DoDirectWrites(); } ModularWriting mr = new ModularWriting(); mr.DoWrite(); b.Flush(); Console.WriteLine("Readline"); Console.ReadLine(); }