C#中错误日志记录方法,信息比较详细易定位
2017年06月06日 11:39:13 smartsmile2012 阅读数 2218
版权声明:本文为博主原创文章,未经博主允许不得转载,如文章对您有帮助,请页面左侧随意打赏。 https://blog.csdn.net/smartsmile2012/article/details/72876577
-
namespace Sample3
-
{
-
class Program
-
{
-
static void Main(string[] args)
-
{
-
try
-
{
-
int i = Convert.ToInt32("a");
-
}
-
catch (Exception)
-
{
-
TraceMessage("Something happened.");
-
}
-
Console.ReadLine();
-
}
-
private static void TraceMessage(string message,
-
[System.Runtime.CompilerServices.CallerMemberName] string memberName = "",
-
[CallerFilePath] string sourceFilePath = "",
-
[CallerLineNumber] int sourceLineNumber = 0)
-
{
-
Console.WriteLine("message: " + message);
-
Console.WriteLine("member name: " + memberName);
-
Console.WriteLine("source file path: " + sourceFilePath);
-
Console.WriteLine("source line number: " + sourceLineNumber);
-
}
-
}
-
}