日志文件生成 [英] log files generation

查看:89
本文介绍了日志文件生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个将excel_to_db和db_to_excel转换的应用程序.我想以文本格式将日志文件生成到我的应用程序中,即将其转换为errorlog.txt文件,这对我有帮助.



谢谢与问候,
srinath.pothineni

hello everybody,
I have an application that converts excel_to_db and db_to_excel.I want to generate log files to my application in a text format i.e into errorlog.txt file help me for the solution.




Thanks & Regards,
srinath.pothineni

推荐答案

您知道代码的详细信息以及要记录的内容. Server.MapPath("/App_Data")将为您提供一个文件系统路径,您可以将其写入此位置. System.IO.File.WriteAllText是编写您创建的日志文本的最简单方法.
You know the details of your code, and what you want to log. Server.MapPath("/App_Data") will give you a file system path to one place you could write this. System.IO.File.WriteAllText is the easiest way to write the text of the log you create.


我建​​议您阅读这篇有趣的文章,以使基础更加清晰
http://www.dotnetfunda .com/articles/article1142-debugging-tracing-and-instrumentation-in-net-and-aspnet-14-faq-.aspx [
I Suggest read this interesting article, for the base to be more clear
http://www.dotnetfunda.com/articles/article1142-debugging-tracing-and-instrumentation-in-net-and-aspnet-14-faq-.aspx[^]


您是否正在使用第3部分应用程序进行转换.如果是,那么您别无选择地记录错误.

如果应用程序是由您编写的,那么很容易记录您的错误.

在将数据传输到另一个数据库的代码中,通过插入语句,您需要捕获catch异常.发生任何错误,您需要更新日志文本文件.

Are you using a 3rd paty application to convert. If yes, then you have no choice to log error.

If the application is written by you, the it is pretty straight forward to log your error.

In the code where you are transferring data to another database, by insert statement, you need to trap the catch exception. Any error, you need to update the log text file.

try{
  //your code - inserting/updating data or bulk insert/update
}
catch(SqlException ex){
  //create error log
  //take the detail exception string from ex and generate a string with other details you want and send it to a text file.
}



希望有帮助.
欢呼



Hope this help.
cheers


这篇关于日志文件生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆