Exemple #1
0
        public static void CanDeserializeComplexEntry()
        {
            var entry = new LogEntry(LogLevel.Debug, "DEBUG", new Json[] { "arg" });
            entry.Tag("tag");
            entry.AttachObject("two", 2);
            var json = JsonConvert.SerializeObject(entry);

            var reconstructedEntry = JsonConvert.DeserializeObject<LogEntry>(json);

            Assert.AreEqual(entry, reconstructedEntry);
        }
Exemple #2
0
        public static void CanSerializeComplexEntryToJson()
        {
            var entry = new LogEntry(LogLevel.Debug, "DEBUG", new Json[] { "arg" });
            entry.Tag("tag");
            entry.AttachObject("two", 2);
            var dt = entry.DateTime;
            var dtstr = dt.ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFFZ");
            var expectedJson = String.Format("{{\"DateTime\":\"{0}\",\"LogLevel\":{1},\"Message\":\"{2}\",\"TagList\":[\"tag\"],\"Parameters\":{{\"0\":\"arg\"}},\"Attachments\":{{\"two\":2}}}}", dtstr, (int)LogLevel.Debug, "DEBUG");
            var json = JsonConvert.SerializeObject(entry);

            Assert.AreEqual(expectedJson, json);
        }
            public override void Log(LogEntry logEntry)
            {
                foreach (var tag in TagList)
                {
                    logEntry.Tag(tag);
                }

                foreach (var kv in AttachObjects)
                {
                    var key = kv.Key;
                    var obj = kv.Value;

                    logEntry.AttachObject(key, obj);
                }
            }