Exemplo n.º 1
0
        public void SerializeDeserializeLogMessage_withNestedException()
        {
            var ser = new BSONSerializer(new BSONTypeResolver(typeof(Message)));

            var msg = new NFX.Log.Message
            {
                Type              = MessageType.DebugGlue,
                TimeStamp         = App.TimeSource.UTCNow,
                Channel           = "MTV",
                From              = "Zhaba",
                Topic             = "App",
                Text              = "Hello text in Chinese: 中原千军逐蒋",
                Source            = 0,
                Parameters        = new string('a', 128000),
                ArchiveDimensions = "a=1 b=2",
                Exception         = WrappedException.ForException(new Exception("It is an error!!!", new Exception("Inside")))
            };

            var doc = ser.Serialize(msg);

            Console.WriteLine(doc.ToJSON(JSONWritingOptions.PrettyPrint));

            var got = ser.Deserialize(doc) as NFX.Log.Message;

            testMsgEquWoError(msg, got);

            Aver.IsTrue(got.Exception is WrappedException);
            Aver.AreEqual(msg.Exception.Message, got.Exception.Message);
            Aver.AreEqual(((WrappedException)msg.Exception).Wrapped.Message, ((WrappedException)got.Exception).Wrapped.Message);
            Aver.IsNotNull(((WrappedException)msg.Exception).Wrapped.InnerException);

            Aver.AreEqual(((WrappedException)msg.Exception).Wrapped.InnerException.Message, ((WrappedException)got.Exception).Wrapped.InnerException.Message);
        }
Exemplo n.º 2
0
        public void SerializeDeserializeLogMessage_KnownTypes()
        {
            var ser = new BSONSerializer();//notice no resolver

            var msg = new NFX.Log.Message
            {
                Type              = MessageType.DebugGlue,
                TimeStamp         = App.TimeSource.UTCNow,
                Channel           = "MTV",
                From              = "Zhaba",
                Topic             = "App",
                Text              = "Hello text",
                Source            = 12345,
                Parameters        = "aaaaa",
                ArchiveDimensions = "a=1 b=2"
            };

            var doc = ser.Serialize(msg, new BSONParentKnownTypes(typeof(Message)));

            Console.WriteLine(doc.ToJSON(JSONWritingOptions.PrettyPrint));

            Aver.IsFalse(doc.IndexOfName(ser.TypeIDFieldName) >= 0); //field was NOT added as the root type is known

            var got = new NFX.Log.Message();                         //pre-allocate before deserialize, as __t was not emitted

            Aver.IsNotNull(ser.Deserialize(doc, result: got) as NFX.Log.Message);
            testMsgEquWoError(msg, got);
        }
Exemplo n.º 3
0
        public void SerializeDeserializeLogMessage()
        {
            var ser = new BSONSerializer(new BSONTypeResolver(typeof(Message)));

            var msg = new NFX.Log.Message
            {
                Type              = MessageType.DebugGlue,
                TimeStamp         = App.TimeSource.UTCNow,
                Channel           = "MTV",
                From              = "Zhaba",
                Topic             = "App",
                Text              = "Hello text",
                Source            = 12345,
                Parameters        = "aaaaa",
                ArchiveDimensions = "a=1 b=2"
            };

            var doc = ser.Serialize(msg);

            Console.WriteLine(doc.ToJSON(JSONWritingOptions.PrettyPrint));


            Aver.IsTrue(doc.IndexOfName(ser.TypeIDFieldName) >= 0);//field was added

            var got = ser.Deserialize(doc) as NFX.Log.Message;

            testMsgEquWoError(msg, got);
        }
Exemplo n.º 4
0
        private void log(MessageType type, string from, string msg, Exception error = null, Guid?batch = null)
        {
            var lm = new NFX.Log.Message {
                Type      = type,
                Topic     = SysConsts.LOG_TOPIC_ID_GEN,
                From      = from,
                Text      = msg,
                Exception = error
            };

            if (batch.HasValue)
            {
                lm.RelatedTo = batch.Value;
            }

            App.Log.Write(lm);
        }
Exemplo n.º 5
0
        protected void Log(MessageType type, string from, string msg, Exception error = null, Guid?batch = null)
        {
            var lm = new NFX.Log.Message {
                Type      = type,
                Topic     = SysConsts.LOG_TOPIC_ID_GEN,
                From      = "{0}.{1}".Args(GetType().Name, from),
                Text      = msg,
                Exception = error
            };

            if (batch.HasValue)
            {
                lm.RelatedTo = batch.Value;
            }

            App.Log.Write(lm);
        }
Exemplo n.º 6
0
        private void log(MessageType type, string from, string text, Exception error = null, Guid?related = null)
        {
            var msg = new NFX.Log.Message
            {
                Type      = type,
                Topic     = SysConsts.LOG_TOPIC_INSTRUMENTATION,
                From      = "{0}.{1}".Args(GetType().FullName, from),
                Text      = text,
                Exception = error
            };

            if (related.HasValue)
            {
                msg.RelatedTo = related.Value;
            }

            App.Log.Write(msg);
        }
Exemplo n.º 7
0
        private void testMsgEquWoError(NFX.Log.Message msg, NFX.Log.Message got)
        {
            Aver.IsNotNull(got);
            Aver.AreNotSameRef(msg, got);

            Aver.AreEqual(msg.Guid, got.Guid);
            Aver.AreEqual(msg.RelatedTo, got.RelatedTo);
            Aver.AreEqual(msg.Host, got.Host);
            Aver.AreEqual(msg.TimeStamp, got.TimeStamp);

            Aver.IsTrue(msg.Type == got.Type);
            Aver.AreEqual(msg.Channel, got.Channel);
            Aver.AreEqual(msg.From, got.From);
            Aver.AreEqual(msg.Topic, got.Topic);
            Aver.AreEqual(msg.Text, got.Text);
            Aver.AreEqual(msg.Source, got.Source);
            Aver.AreEqual(msg.Parameters, got.Parameters);
            Aver.AreEqual(msg.ArchiveDimensions, got.ArchiveDimensions);
        }