Beispiel #1
0
 public override void OnEntry(Entry e) {
     lock (lockObj) {
         Prepare();
         Write(e, -1);
         file.Flush();
     }
 }
Beispiel #2
0
 private void AddEntry(Entry entry)
 {
     if (Context.Count == 0)
     {
         lock (Entries)
         {
             Entries.Add(entry);
         }
     }
     else
     {
         Context.Peek().Entries.Add(entry);
     }
     try
     {
         if (OnEntry != null)
         {
             lock (Entries)
             {
                 OnEntry(entry);
             }
         }
     }
     catch (Exception ex)
     {
         log.Error(null, ex);
     }
 }
Beispiel #3
0
 public bool Equals(Entry e)
 {
     return
         Type == e.Type &&
         Description == e.Description &&
         Offset == e.Offset &&
         Duration == e.Duration &&
         Entries.Intersect(e.Entries).Count() == Entries.Count &&
         Properties.Intersect(e.Properties).Count() == Properties.Count;
 }
        public void BrokerSMIAppenderTest()
        {
            var trace = TraceManager.BeginTrace();
            var brokerAppender = TraceManager_Accessor.appenders.Where(a => a is pt.sapo.gis.trace.appender.SMI.BrokerSMILoggerAppender).FirstOrDefault() as pt.sapo.gis.trace.appender.SMI.BrokerSMILoggerAppender;

            var broker = new SapoBrokerClient.BrokerClient(new SapoBrokerClient.HostInfo(brokerAppender.Properties.Host, brokerAppender.Properties.Port));
            var subscription = new SapoBrokerClient.Subscription(brokerAppender.Properties.Topic, SapoBrokerClient.NetAction.DestinationType.TOPIC);
            JObject report = null;
            var ev = new ManualResetEvent(false);
            subscription.OnMessage += m =>
            {
                var str = new StringWriter();
                var jsonSer = new Newtonsoft.Json.JsonSerializer();
                report = JObject.Parse(Encoding.UTF8.GetString(m.Message.Payload));
                ev.Set();
            };
            broker.Subscribe(subscription);
            var e = new pt.sapo.gis.trace.Entry
            {
                Type = "UNKNOWN",
                Description = "Who knowns...",
                Severity = pt.sapo.gis.trace.configuration.severityType.FATAL,
                Properties = new Dictionary<String, Object> { { "a", "1" }, { "b", "foo" } }
            };
            trace.TraceEntry(e);
            if (ev.WaitOne(TimeSpan.FromSeconds(10)) == false)
                Assert.Fail("Broker message doesn't arrive.");
            Assert.IsNotNull(report["SourceID"]);
            var defaultSourceId = TraceManager_Accessor.appenders.Where(a => a is BrokerSMILoggerAppender).Cast<BrokerSMILoggerAppender>().First().Properties.DefaultSourceId;
            Assert.AreEqual(defaultSourceId, report["SourceID"]);
            Assert.IsNotNull(report["DateTime"]);
            var state = report["State"];
            Assert.IsNotNull(state);
            Assert.IsNotNull(state["Health"]);
            Assert.AreEqual(pt.sapo.sdb.smi.HealthState.OperationalWithFailures.ToString(), state["Health"]);
            Assert.IsNotNull(state["Execution"]);
            Assert.AreEqual(pt.sapo.sdb.smi.ExecutionState.Active.ToString(), state["Execution"]);
            Assert.IsNotNull(state["Failures"]);
            Assert.AreEqual(1, state["Failures"].Count());
            var failure = state["Failures"].First();
            Assert.IsNotNull(failure["FailureID"]);
            Assert.AreEqual(e.Type.ToString(), failure["FailureID"]);
            Assert.AreEqual(defaultSourceId, failure["SourceID"]);
            var details = failure["Details"];
            Assert.IsNotNull(details);
            Assert.IsNotNull(details["a"]);
            Assert.AreEqual(JTokenType.String, details["a"].Type);
            Assert.AreEqual("1", details["a"]);
            Assert.IsNotNull(details["b"]);
            Assert.AreEqual(JTokenType.String, details["b"].Type);
            Assert.AreEqual("foo", details["b"]);
            Assert.IsNotNull(report["Metrics"]);
            Assert.IsNotNull(report["ActivityID"]);
            Assert.IsNotNull(report["AgentID"]);
        }
Beispiel #5
0
 protected virtual void Write(Entry e, int deep) {
     for (int i = -1; i < deep; ++i)
         file.Write("..");            
     file.WriteLine("ENTRY: '{0}', offset: {1:0.000}, duration: {2:0.000}, severity: {3}, properties: [{4}]", 
             e.Description, 
             e.Offset, 
             e.Duration, 
             e.Severity, 
             string.Join(";", e.Properties.Select((k,v) => k+":"+v.ToString())));
     if (deep != -1) {
         foreach (Entry se in e.Entries) {
             Write(se, deep + 1);
         }
     }
 }
Beispiel #6
0
 /// <summary>
 /// Trace a new entry
 /// </summary>
 /// <param name="entry">entry the entry to add to the trace</param>
 public void TraceEntry(Entry entry)
 {
     entry.Parent = this;
     entry.Offset = stopwatch.ElapsedMilliseconds;
     AddEntry(entry);
 }
Beispiel #7
0
 private void GetEntrySeverityTypes(Entry entry, ISet<severityType> severities)
 {
     severities.Add(entry.Severity);
     foreach (Entry e in entry.Entries)
     {
         GetEntrySeverityTypes(e, severities);
     }
 }
Beispiel #8
0
 ///
 /// <summary>Start a new entry context. Every entry added after this will be added as sub entry of this one.</summary>
 /// <param name="entry">the entry to start the new context     </param>
 public Entry BeginEntry(Entry entry)
 {
     entry.Offset = stopwatch.ElapsedMilliseconds;
     entry.Parent = this;
     Context.Push(entry);
     return entry;
 }