Duality.Log.Exception C# (CSharp) Method

Exception() public static method

Returns a string that can be used for representing an exception in log entries. It usually does not include the full call stack and is significantly shorter than an Exceptions ToString method.
public static Exception ( Exception e, bool callStack = true ) : string
e System.Exception
callStack bool
return string
        public static string Exception(Exception e, bool callStack = true)
        {
            if (e == null) return null;

            string eName = Type(e.GetType());
            string eSite = e.TargetSite != null ? MemberInfo(e.TargetSite) : null;

            return string.Format(System.Globalization.CultureInfo.InvariantCulture,
                "{0}{1}: {2}{4}CallStack:{4}{3}",
                eName,
                eSite != null ? " at " + eSite : "",
                e.Message,
                e.StackTrace,
                Environment.NewLine);
        }

Usage Example

Esempio n. 1
0
        private static Resource ResolveContent(string path)
        {
            if (string.IsNullOrEmpty(path) || ResourceResolve == null)
            {
                return(null);
            }

            ResourceResolveEventArgs args = new ResourceResolveEventArgs(path);

            try
            {
                ResourceResolve(null, args);
            }
            catch (Exception e)
            {
                Log.Core.WriteError("An error occurred in custom ResourceResolve code: {0}", Log.Exception(e));
            }

            if (args.Handled)
            {
                if (string.IsNullOrEmpty(args.Result.Path))
                {
                    args.Result.Path = path;
                }
                AddContent(path, args.Result);
                return(args.Result);
            }
            else
            {
                return(null);
            }
        }