public static void Run() { var svc = new LogService(null); var dest = new ConsoleDestination("konzol"); dest.Colored = true; var filter = new FloodFilter(dest) { Interval = TimeSpan.FromSeconds(3d) }; //filter.MinLevel = MessageType.Error; //filter.MaxLevel = MessageType.Info; svc.RegisterDestination(filter); svc.Start(); svc.Write(new Message { Type = MessageType.Info, Text = "This is info", From = "Tukhis" }); System.Threading.Thread.Sleep(4000); svc.Write(new Message { Type = MessageType.Warning, Text = "Warning text goes here", From = "Beitzhen" }); System.Threading.Thread.Sleep(3500); svc.Write(new Message { Type = MessageType.Error, Text = "This is error line", From = "Moisha" }); for (var i = 0; i < 1000000; i++) { svc.Write(new Message { Type = MessageType.Info, Text = "Loop trakhen" + i.ToString(), From = "Loop" }); } svc.WaitForCompleteStop(); }
public void ShouldTriggerWriteLineWhenLoggingMessage() { //setup const string msg = "Hello World!"; var mWrapper = new Mock <ConsoleDestination.ConsoleWrapper>(); mWrapper.Setup(w => w.WriteLine(It.IsAny <string>())).Verifiable(); var dest = new ConsoleDestination(LogLevels.Debug, mWrapper.Object); Utilities.Logger.AddDestination(dest); //act Utilities.Logger.Debug(msg); //assert mWrapper.VerifyAll(); //cleanup Utilities.Logger.RemoveDestination(dest); }
public void AddDestination(TypeDestination Type) { Destination destination; if (Type == TypeDestination.TypeFile) { destination = new FileDestination(); } else if (Type == TypeDestination.TypeConsole) { destination = new ConsoleDestination(); } else { return; } destination.Category = Name; destination.Initialize(Name); listDestination.Add(destination); }
public void Program() { // different destinations where sessions can be dumped: var consoleDestination = new ConsoleDestination(); var networkPacketBuilder = new NetworkPacketBuilder(); var fileDestination1 = new FileStorageFormat1(); var fileDestination2 = new FileStorageFormat2(); var devNull = new DevNull(); var populationOfOwnersListOnGui = new PopulationOfOwnersListOnGui(new WpfBasedOwnersList()); /////////////////////////////////////// // 1. Hiding access to sessions allows protecting the collection against // concurrent additions with synchronized wrapper Sessions sessions = new SynchronizedSessions(new BasicSessions()); AddExemplaryDataTo(sessions); /////////////////////////////////////// // 2. These two prove that we have eliminated redundancy in: // a) what data belongs to session // b) in which order they are dumped sessions.DumpTo(consoleDestination); sessions.DumpTo(fileDestination1); /////////////////////////////////////// // 3. These three prove that we have not lost flexibility we had with the getters approach: // additionally these two always want to write _all_ of the session fields, so they belong to 2.a. as well sessions.DumpTo(fileDestination2); sessions.DumpTo(networkPacketBuilder); var networkConnection = new BogusNetworkConnection(); networkPacketBuilder.SendBuiltPacketsThrough(networkConnection); sessions.DumpTo(populationOfOwnersListOnGui); sessions.DumpTo(devNull); }
/// <summary> /// Adds a destination that writes to the console. /// All destinations will be used when creating a logger from a LoggerPool. /// </summary> /// <param name="useColors"></param> /// <returns></returns> public static LogAdministrator AddConsoleDestination(this LogAdministrator logAdministrator, bool useColors = false) { var destination = new ConsoleDestination(useColors); return(logAdministrator.AddCustomDestination(destination)); }