using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tango.Logging
{
///
/// Represents an exception log item.
///
[Serializable]
public class ExceptionLogItem : LogItemBase
{
///
/// Gets or sets the log item exception.
///
public Exception Exception { get; set; }
///
/// Gets or sets the error description.
///
public String Description { get; set; }
///
/// Gets the log message.
///
public override string Message
{
get
{
if (Exception is AggregateException)
{
try
{
String message = String.Empty;
if (Description != null)
{
message += Description + Environment.NewLine;
}
message += String.Join(Environment.NewLine, (Exception as AggregateException).InnerExceptions.Select(x => x.Message));
return message;
}
catch
{
return Exception.Message;
}
}
else
{
return Exception.Message;
}
}
set { }
}
///
/// Returns a formatted string of the log item.
///
public override string ToString()
{
return String.Format("[{0}] [{6}] [{1}] [{2}] [{3}]: {4}{5}", TimeStamp.ToString("HH:mm:ss.ff"), GetRelativeCallerFilePath(), CallerMethodName, CallerLineNumber, Description, Environment.NewLine + Exception.FlattenException(), Category);
}
}
}