コード例 #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);
        }
コード例 #2
0
ファイル: Message.cs プロジェクト: uzbekdev1/nfx
        public void SerializeToBSON(BSONSerializer serializer, BSONDocument doc, IBSONSerializable parent, ref object context)
        {
            serializer.AddTypeIDField(doc, parent, this, context);

            var skipNull = (serializer.Flags ^ BSONSerializationFlags.KeepNull) == 0;

            doc.Add(serializer.PKFieldName, m_Guid, required: true)
            .Add(BSON_FLD_RELATED_TO, m_RelatedTo, skipNull)
            .Add(BSON_FLD_TYPE, m_Type.ToString(), skipNull, required: true)
            .Add(BSON_FLD_SOURCE, m_Source, skipNull)
            .Add(BSON_FLD_TIMESTAMP, m_TimeStamp.ToUniversalTime(), skipNull)
            .Add(BSON_FLD_HOST, m_Host, skipNull)
            .Add(BSON_FLD_FROM, m_From, skipNull)
            .Add(BSON_FLD_TOPIC, m_Topic, skipNull)
            .Add(BSON_FLD_TEXT, m_Text, skipNull)
            .Add(BSON_FLD_PARAMETERS, m_Parameters, skipNull)
            .Add(BSON_FLD_ARCHIVE_DIMENSIONS, m_ArchiveDimensions, skipNull)
            .Add(BSON_FLD_CHANNEL, m_Channel, skipNull);

            if (m_Exception == null)
            {
                return;
            }

            var we = m_Exception as WrappedException;

            if (we == null)
            {
                we = WrappedException.ForException(m_Exception);
            }

            doc.Add(BSON_FLD_EXCEPTION, serializer.Serialize(we, parent: this), skipNull);
        }
コード例 #3
0
        public void SerializeDeserializeLogMessage_withException()
        {
            var ser = new BSONSerializer(new BSONTypeResolver(typeof(Message)));

            var msg = new Azos.Log.Message
            {
                Type              = MessageType.DebugGlue,
                UTCTimeStamp      = Ambient.UTCNow,
                Channel           = "MTV",
                From              = "Zhaba",
                Topic             = "App",
                Text              = "Hello text",
                Source            = 12345,
                Parameters        = "aaaaa",
                ArchiveDimensions = "a=1 b=2",
                Exception         = WrappedException.ForException(new Exception("It is an error!!!"))
            };

            var doc = ser.Serialize(msg);

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

            var got = ser.Deserialize(doc) as Azos.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);
        }
コード例 #4
0
ファイル: Message.cs プロジェクト: uzbekdev1/nfx
        public static Message ThisOrNewSafeWrappedException(this Message msg, bool captureStack = true)
        {
            if (msg == null || msg.Exception == null || msg.Exception is WrappedException)
            {
                return(msg);
            }

            var clone = msg.Clone();

            clone.Exception = WrappedException.ForException(msg.Exception, captureStack);
            return(clone);
        }