public override object convert(LogBase data, bool is_sub = false) { StringBuilder sbuilder = new StringBuilder(); sbuilder.Append(string.Format("{0,-20}", data.TimeStamp.ToString(timeformat))); sbuilder.Append(" | "); sbuilder.Append(string.Format("{0,-6}", data.MessageType.ToString().Substring(0, 4).ToUpper())); sbuilder.Append(" | "); //If Property name is not null, provide it. if (!string.IsNullOrEmpty(data.Name)) { sbuilder.Append("Prop Name - " + data.Name); sbuilder.Append(" | "); } //Add if KVP if (data.GetType() == typeof(DictionaryLog)) { sbuilder.Append("Key : " + ((DictionaryLog)data).Key); sbuilder.Append(" | "); sbuilder.Append("Value : " + ((DictionaryLog)data).Value); sbuilder.Append(" | "); } //Add message if (!string.IsNullOrEmpty(data.Message)) { sbuilder.Append(data.Message); sbuilder.Append(" | "); } //Add if dictionary if (data.GetType() == typeof(ExceptionLog)) { sbuilder.Append("Exception Message : " + ((ExceptionLog)data).ExceptionMessage); sbuilder.Append(" | "); sbuilder.Append("Trace : " + ((ExceptionLog)data).Trace); sbuilder.Append(" | "); } if (is_sub) { return($@"***SUBLOG*** | " + sbuilder.ToString()); //if sub add sub log } return(sbuilder.ToString()); }
public override object convert(LogBase data, bool is_sub = false) { StringBuilder sbuilder = new StringBuilder(); if (is_sub) { sbuilder.AppendLine("#####*****---- BEGIN SUB LOG ----*****#####"); } else { sbuilder.AppendLine("---- BEGIN LOG ----"); } //Get timestamp sbuilder.AppendLine(nameof(data.TimeStamp) + " : " + data.TimeStamp.ToString(timeformat)); //Get PropertyName if (!string.IsNullOrEmpty(data.Name)) { sbuilder.AppendLine(nameof(data.Name) + " : " + data.Name); } //Get the main message if present if (!string.IsNullOrEmpty(data.Message)) { sbuilder.AppendLine(nameof(data.Message) + " : " + data.Message); } //Get the Info Type sbuilder.AppendLine(nameof(data.MessageType) + " : " + data.MessageType.ToString()); //Get Further Data if it is exception type if (data.GetType() == typeof(ExceptionLog)) { ExceptionLog _excplog = (ExceptionLog)data; if (!string.IsNullOrEmpty(_excplog.ExceptionMessage)) { sbuilder.AppendLine(nameof(_excplog.ExceptionMessage) + " : " + _excplog.ExceptionMessage); } if (!string.IsNullOrEmpty(_excplog.Trace)) { sbuilder.AppendLine(nameof(_excplog.Trace) + " : " + _excplog.Trace); } } //Get data if it is property type if (data.GetType() == typeof(DictionaryLog)) { DictionaryLog _dicLog = (DictionaryLog)data; if (!string.IsNullOrEmpty(_dicLog.Key)) { sbuilder.AppendLine(nameof(_dicLog.Key) + " : " + _dicLog.Key); } if (!string.IsNullOrEmpty(_dicLog.Value)) { sbuilder.AppendLine(nameof(_dicLog.Value) + " : " + _dicLog.Value); } } if (is_sub) { sbuilder.AppendLine("#####*****---- END SUB LOG ----*****#####"); } else { sbuilder.AppendLine("---- END LOG ----"); } return(sbuilder.ToString()); }