public void CreateByCodeOwnDaemon() { using (var logger = new LogDaemon(NOPApplication.Instance)) { logger.WriteInterval = 0; //set the minimum flush period Aver.Throws <AzosException>(() => logger.Start()); //can not start daemon with no sinks Aver.IsFalse(logger.Running); Aver.IsFalse(logger.Sinks.Any()); using (var sink = new MemoryBufferSink(logger)) { sink.Name.See(); Aver.IsTrue(sink.Name.StartsWith("MemoryBufferSink.")); //anonymous sinks get their name from their: 'type.fid' logger.Start(); //now it can start Aver.IsTrue(logger.Running); Aver.AreSameRef(sink, logger.Sinks.First()); //now there is a sink registered which is this one Aver.IsTrue(sink.Running); //it was auto-started by the logger logger.Write(new Message { Type = MessageType.DebugB, Text = "This is a message #1" }); //so this messages goes in it Thread.Sleep(DAEMON_FLUSH_WAIT_MS); //make sure async flush happens Aver.IsTrue(sink.Buffered.Any()); //because sink was active var logged = sink.Buffered.FirstOrDefault(); // we get the first message buffered Aver.AreEqual("This is a message #1", logged.Text); Aver.IsTrue(MessageType.DebugB == logged.Type); sink.WaitForCompleteStop();//stop the sink Aver.IsFalse(sink.Running); logger.Write(new Message { Type = MessageType.Debug, Text = "This is a message #2" }); Thread.Sleep(DAEMON_FLUSH_WAIT_MS); //make sure async flush happens Aver.AreEqual(1, sink.Buffered.Count()); //because sink was not turned on for 2nd, only the first message got in, 2nd got lost } Aver.IsFalse(logger.Sinks.Any());//again, no sinks left } }
/// <summary> /// Creates a singleton instance or throws if instance is already created /// </summary> public ZoneGovernorService(IApplication app) : base(app) { if (!App.Singletons.GetOrCreate(() => this).created) { throw new AZGOVException(Sky.StringConsts.AZGOV_INSTANCE_ALREADY_ALLOCATED_ERROR); } m_SubInstr = new InstrumentationDaemon(this); m_SubInstrReductionLevels = new Dictionary <string, int>(); m_SubInstrCallers = new ConcurrentDictionary <string, DateTime>(); m_SubLog = new LogDaemon(this); m_SubHosts = new Registry <HostInfo>(); m_DynamicHostSlots = new Registry <DynamicHostInfo>(); m_Locker = new LockServerService(this); }
public LogDaemonSink(ISinkOwner owner, string name, int order) : base(owner, name, order) { m_Daemon = new LogDaemon(this); }
public LogDaemonSink(ISinkOwner owner) : base(owner) { m_Daemon = new LogDaemon(this); }
public listSink(LogDaemon owner) : base(owner, "test-sink", -1) { }