From de5315c050369dd7d2cc7cdc2b82e9cde0d6da24 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 21 Jan 2019 18:27:13 +0200 Subject: Testing some external bridge communication.. Implemented external bridge application logs routing !!! --- .../Tango.Logging/ExceptionLogItem.cs | 1 + .../Visual_Studio/Tango.Logging/LogItemBase.cs | 39 +++++++++++++++++++++- Software/Visual_Studio/Tango.Logging/LogManager.cs | 9 +++++ .../Visual_Studio/Tango.Logging/MessageLogItem.cs | 1 + 4 files changed, 49 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/Tango.Logging') diff --git a/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs b/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs index d2a1a352d..7c325ee19 100644 --- a/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs +++ b/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs @@ -10,6 +10,7 @@ namespace Tango.Logging /// /// Represents an exception log item. /// + [Serializable] public class ExceptionLogItem : LogItemBase { /// diff --git a/Software/Visual_Studio/Tango.Logging/LogItemBase.cs b/Software/Visual_Studio/Tango.Logging/LogItemBase.cs index b914a33ef..f89b73b40 100644 --- a/Software/Visual_Studio/Tango.Logging/LogItemBase.cs +++ b/Software/Visual_Studio/Tango.Logging/LogItemBase.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; +using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Threading.Tasks; @@ -11,14 +12,21 @@ namespace Tango.Logging /// /// Represents a base class for log items. /// + [Serializable] public abstract class LogItemBase : INotifyPropertyChanged { private static String base_path; + [NonSerialized] + private Object _logObject; /// /// Gets or sets an optional log object. /// - public Object LogObject { get; set; } + public Object LogObject + { + get { return _logObject; } + set { _logObject = value; } + } /// /// Gets or sets the caller method adding the exception. @@ -86,6 +94,35 @@ namespace Tango.Logging } } + /// + /// Serializes this log item using . + /// + /// + public byte[] Serialize() + { + using (MemoryStream ms = new MemoryStream()) + { + BinaryFormatter f = new BinaryFormatter(); + f.Serialize(ms, this); + return ms.ToArray(); + } + } + + /// + /// Deserializes the specified data using to create a log item. + /// + /// The data. + /// + public static LogItemBase Deserialize(byte[] data) + { + using (MemoryStream ms = new MemoryStream(data)) + { + ms.Position = 0; + BinaryFormatter f = new BinaryFormatter(); + return f.Deserialize(ms) as LogItemBase; + } + } + /// /// Raises the property changed event. /// diff --git a/Software/Visual_Studio/Tango.Logging/LogManager.cs b/Software/Visual_Studio/Tango.Logging/LogManager.cs index 04c66a71f..98bcaaa28 100644 --- a/Software/Visual_Studio/Tango.Logging/LogManager.cs +++ b/Software/Visual_Studio/Tango.Logging/LogManager.cs @@ -189,6 +189,15 @@ namespace Tango.Logging return message; } + /// + /// Appends the specified log item. + /// + /// The log item. + public void Log(LogItemBase logItem) + { + AppendLog(logItem); + } + /// /// Logs the current referenced assemblies in the app domain. /// diff --git a/Software/Visual_Studio/Tango.Logging/MessageLogItem.cs b/Software/Visual_Studio/Tango.Logging/MessageLogItem.cs index f45aa8cea..b0b3e24ae 100644 --- a/Software/Visual_Studio/Tango.Logging/MessageLogItem.cs +++ b/Software/Visual_Studio/Tango.Logging/MessageLogItem.cs @@ -10,6 +10,7 @@ namespace Tango.Logging /// /// Represents an exception log item. /// + [Serializable] public class MessageLogItem : LogItemBase { private String _message; -- cgit v1.3.1