您的位置:首页 > 编程语言 > C#

C#中错误日志记录方法,信息比较详细易定位

2017-06-06 11:39 831 查看
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);
}
}
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐