如何在控制台应用程序中创建日志报告?
问题描述:
嗨
我有一个控制台应用程序,因为如果我有任何错误,所以只需使用Console.Write(错误消息)在控制台屏幕上显示消息。
但是现在,我想做,记录报告
每当应用程序生成任何错误时,我必须收到我的id上的邮件,并显示错误消息。
喜欢在web应用程序中,我们可以在Global.asax文件的Application_Error()中写入。
做回复。
谢谢。
Hi
I have one console application, in that if i got any error so simply used Console.Write("error message ") which shows message on console screen.
But now , i want to do , log report
whenever any error generated by application , i have to get mail on my id , with error message.
like in web application , we can write in Application_Error() of Global.asax file.
Do reply.
Thank you.
答
控制台应用与否,无所谓。你有一个总是有效的日志机制,Windows服务的事件(比其他应用程序更难调试):
这个来自.NET BCL:http://msdn.microsoft.com/en-us/library/vstudio/system.diagnostics.eventlog [ ^ ]。
这是开源替代方案:Apache log4net:
http://en.wikipedia.org/wiki/Log4net [ ^ ],
http://en.wikipedia.org/ wiki / Log4net #Ports [ ^ ],
http://msdn.microsoft.com/en-us/library/vstudio/system.diagnostics.eventlog [ ^ ]。
此CodeProject文章也很有用: log4net教程 [ ^ ]。-SA
Console application or not, does not matter. You have a log mechanism which always works, event for Windows Services (which are much more difficult to debug then other applications):
This one is from .NET BCL: http://msdn.microsoft.com/en-us/library/vstudio/system.diagnostics.eventlog[^].
And this is the open-source alternative: Apache log4net:
http://en.wikipedia.org/wiki/Log4net[^],
http://en.wikipedia.org/wiki/Log4net#Ports[^],
http://msdn.microsoft.com/en-us/library/vstudio/system.diagnostics.eventlog[^].
This CodeProject article can also be useful: log4net Tutorial[^].—SA
您可以使用log4net。 log4net教程 [ ^ ]
You can use log4net. log4net Tutorial[^]
我使用但是它无效。
但感谢您回复。
i used but it was not working.
but thankx for response.