namespace JD.Nas.Reporting.Console.Module.Exception { using JD.Nas.Reporting.Console.Module.Constants; using System; using System.Runtime.CompilerServices; public class ReportingConsoleException: Exception { private Guid _id = Guid.NewGuid(); private ReportingConsoleExitCode? _exitCode; private string _error; private string _methodName; public ReportingConsoleException(ReportingConsoleExitCode exitCode, string message = null, [CallerMemberName] string callerMemberName = null) : base() { this._error = message; this._methodName = callerMemberName; this._exitCode = exitCode; } public ReportingConsoleException(ReportingConsoleExitCode exitCode, Exception ex, [CallerMemberName] string callerMemberName = null) : base(ex.Message, ex) { this._methodName = callerMemberName; this._exitCode = exitCode; } public int GetExitCodeInt() { return (int)_exitCode; } public Guid GetId() { return this._id; } public string GetIdString() { return this._id.ToString(); } public bool IsToExit() { return this._exitCode.HasValue; } public override string ToString() { string errorMessage; if (!string.IsNullOrEmpty(this._error)) this._error = string.Concat(this._error, " Occured"); else this._error = "An unexpected error as occured"; if (!string.IsNullOrEmpty(this._methodName)) this._error = string.Concat(this._error, " in ", _methodName); if (this.InnerException != null && (!string.IsNullOrEmpty(this.InnerException.Message) || !string.IsNullOrEmpty(this.InnerException.StackTrace))) this._error += "please see exception message"; errorMessage = this._error + '.'; errorMessage = string.Concat(this._error, "[ID]", this.GetIdString()); if (this.IsToExit()) { errorMessage = string.Concat(errorMessage, "[EXITCODE]", this.GetExitCodeInt()); } if (this.InnerException != null && !string.IsNullOrEmpty(this.InnerException.Message)) { errorMessage = string.Concat(errorMessage, "[EXCEPTION]", this.InnerException.Message); } if (this.InnerException != null && !string.IsNullOrEmpty(this.InnerException.StackTrace)) { errorMessage = string.Concat(errorMessage, "[STACKTRACE]", this.InnerException.StackTrace); } return errorMessage; } } }