我一直在寻找一种方法来记录类名和方法名作为我的日志记录基础结构的一部分.显然,我想在运行时使用简单快捷.我已经做了大量关于记录类名和方法名的阅读,但我遇到了2个主题.
如果你幽默我一秒钟,我想重置.
我在我的项目中创建了这样一个类
public static class Log {
private static Dictionary<Type, ILog> _loggers = new Dictionary<Type, ILog>();
private static bool _logInitialized = false;
private static object _lock = new object();
public static string SerializeException(Exception e) {
return SerializeException(e, string.Empty);
}
private static string SerializeException(Exception e, string exceptionMessage) {
if (e == null) return string.Empty;
exceptionMessage = string.Format(
"{0}{1}{2}\n{3}",
exceptionMessage,
(exceptionMessage == string.Empty) ? string.Empty : "\n\n",
e.Message,
e.StackTrace);
if (e.InnerException != null)
exceptionMessage = SerializeException(e.InnerException, exceptionMessage);
return exceptionMessage; …Run Code Online (Sandbox Code Playgroud)