在C#中创建日志文件? [英] Create a log file in c#?

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

问题描述

:confused:我想创建一个日志文件,以便记录由用户在数据库中存储项目引起的所有事件.例如:

:confused:I want to create a logfile so that all events caused by the user to store items on a database are recorded. For instance:

Total records created
Number of records deleted
Date Changes
User Name
Table id


请帮助我在C#中创建此文件.

[edit]主题,整洁和改写-OriginalGriff [/edit]


Please help me to create this file in C#.

[edit]Subject, tidy and rephrase - OriginalGriff[/edit]

推荐答案

您需要确定对数据库和日志文件的处理方式-如果要存储有关用户对数据库执行的每个操作的信息,则日志文件很快就会变得比数据库本身大!
您还需要确定为什么要存储此信息-是否用于审核跟踪?谁去看呢?
此外,您要将日志存储在哪里?如果它位于用户本地计算机上,则将出现权限问题和日志删除问题.如果它在您的服务器上,则存在多用户访问和大量带宽使用的问题.
您可能会发现最好的方法是将日志添加为数据库表或单独的数据库.
想一想,看看Google-看看别人做了什么.
You need to decide what you are going to do with the database, and with the log file - if you are storing info on every action the user takes with the database, then the log file is quickly going to get bigger than the database itself!
You also need to decide why you are going to store this info - is it for an audit trail? Who is going to view it?
Additionally, where are you going to store the log? If it is on the users local machine, then you will have permissions issues, and log deletion issues. If it is on your server, then you have the problem of multiple user access, and a LOT of bandwidth use.
You may find the best thing to do is to add the log as a database table, or as a separate database.
Have a think, and look at Google - see what others have done.


因为您没有指定哪种用户,所以我假设这是任何更改数据库实体的用户.
在这种情况下,这样的日志文件已经存在:它称为数据日志文件:-)
任何数据库都将其与数据文件一起使用.您不需要重新发明轮子.
如果您在谈论应用程序用户,则必须决定要记录的内容,编写日志过程,然后在更改数据库所涉及的过程中调用它.
定义问题时,您必须更加具体.

祝你好运.
Because you did not specify what kind of user, I assume this is any user that changes the database entities.
In this case such log file already exists: it is called data log file :-)
Any database has it together with a data file. You don''t need to re-invent a wheel.
If you are talking about an application user, then you have to decide what you want to log, write log procedure, and call it in the procedures which are involved in changing your database.
You must be more specific when you define the question.

Good luck.


看看log4net- http://www. codeproject.com/KB/aspnet/log4net.aspx [ ^ ].
Have a look at log4net - http://www.codeproject.com/KB/aspnet/log4net.aspx[^].


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

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