private string GetExceptionContent(Exception exception, bool trace, string memberName = null, string sourceFilePath = null, int sourceLineNumber = 0)
{
string methodInfo = null;
if (!String.IsNullOrEmpty(memberName))
{
methodInfo = String.Format("{0}() at {1}:{2}", memberName, sourceFilePath, sourceLineNumber);
}
if (trace)
{
// best effort to handle file system failure.
OperationManager.SafeExecute(() => _traceFactory.GetTracer().TraceError(exception, "{0}", methodInfo));
}
var strb = new StringBuilder();
if (!String.IsNullOrEmpty(methodInfo))
{
strb.AppendLine(methodInfo);
}
strb.AppendLine(exception.ToString());
var aggregate = exception as AggregateException;
if (aggregate != null)
{
foreach (var inner in aggregate.Flatten().InnerExceptions)
{
strb.AppendLine(inner.ToString());
}
}
return strb.ToString();
}
}