如何记录 ASP.NET 应用程序的用户操作?

发布于 2024-09-24 13:57:44 字数 52 浏览 3 评论 0 原文

我们如何记录 ASP.NET 应用程序的用户操作。另外,保存日志数据的方法是什么?请指导。

How can we log user operations for a asp.net application. Further what is the approach for saving the log data ? Kindly guide.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉月流沐 2024-10-01 13:57:44

我建议使用 log4net 或 NLog 等日志框架。这些框架允许您记录到许多目的地,更重要的是,它们允许您在完成应用程序后做出决定,即您可以配置日志消息的写入位置。

就我个人而言,如果是 Web 应用程序,我会登录数据库。

I recommend to use a logging framework like log4net or NLog. These frameworks allow you to log to many destinations and more importantly they allow you to make the decision after you finished your application i.e. you can configure where the log messages are written.

Personally I would log to a database in case of web applications.

失而复得 2024-10-01 13:57:44

或者,您可以使用通用日志记录基础设施来隐藏实现并随意在记录器之间切换
http://netcommon.sourceforge.net

存储日志的位置很大程度上取决于您使用日志的方式记录数据(即读取并解释记录数据,根据需要采取行动)。如果分析日志数据的人有权访问计算机并且这不是业务关键型,则只需记录到文件即可。如果机器对您的业务至关重要,您可能拥有某种监控软件,并且将日志记录发布到事件日志或 WMI 会变得有趣。

如果您记录到文件,请考虑您需要记录数据多长时间以及一次需要多少数据。您可以使用滚动日志文件来确保它们不会变得非常大并占用一半的硬盘空间。您还可以使用过滤器或优先级在没有任何问题时仅记录错误,并在调查问题时打开过滤器进行调试或详细记录。

IIRC log4net 和/或企业库可以记录为 WCF 服务跟踪查看器可读的格式,请参阅 http://msdn.microsoft.com/en-us/library/ms732023.aspx(但我不确定那个)。不过 Log4net 有一个仪表板。

or, you could use the Common Logging infrastructure to hide the implementation and switch between loggers at will
http://netcommon.sourceforge.net

Where you store the logging is largely dictated by how you will consume the logging data(i.e. read and interpret the logging data, take action if needed). If the person who analyzes the logging data has access to the machine and it's not business-critical, just log to file. If the machine is critical to your business you probably have some sort of monitoring software and publishing the logging to event logs or WMI becomes interesting.

If you log to file, consider how long you need the logging data and how much of it you need at one time. You can use rolling log files to make sure they don't become gigantically large and consume half your hard disk space. You can also use filters or priorities to log only errors when there is nothing wrong, and open the filter to debug or verbose when investigating a problem.

IIRC log4net and/or enterprise library can log to a format that is readable by the WCF service trace viewer, see http://msdn.microsoft.com/en-us/library/ms732023.aspx (but i'm not sure about that one). Log4net has a dashboard, though.

感情废物 2024-10-01 13:57:44

有两种方法:将日志详细信息保存到数据库中,或者创建一个简单的文本文件以便可以跟踪事件。

这里我仅给出简单的代码来说明如何跟踪事件并维护日志详细信息并将日志详细信息保存到文本文件中。它可能会帮助您解决您的问题。

首先,您必须导入名称空间:

using System.IO;

我创建了一个小函数来跟踪日志详细信息 -

 public void LogEntry(string msg, string path)
    {
        try
        {
       //It will open the file, append the your message and close the file             
        File.AppendAllText(path,msg);            
        }
        catch (Exception ex)
        {
            ex.GetBaseException();
        }
    }

在这个函数中,您必须传递两个参数

  1. 消息
  2. 文本文件的

路径例如

string logmsg;
 logmsg = "** " + DateTime.Now.ToString() + "||" + "User:" + UserName + "||" + " EventDesc: Login Attempt Failed";
                   l1.LogEntry(logmsg, Server.MapPath("LoginEvent.txt"));

,这里的 LoginEvnet.txt 是我在其中存储日志详细信息的文本文件。

logmsg - 这是您必须跟踪或存储在日志文件中的消息

There are two methods: either you save the log details into the database or create a simple text file so that you can track the events.

Here I am the giving just simple code to how to track the event and maintain the log details and save the log details into the text file. It may help you solve your problem.

First of all you have to import name space:

using System.IO;

I had created the small function to track the log details-

 public void LogEntry(string msg, string path)
    {
        try
        {
       //It will open the file, append the your message and close the file             
        File.AppendAllText(path,msg);            
        }
        catch (Exception ex)
        {
            ex.GetBaseException();
        }
    }

In this function you have to pass the two parameters

  1. Message
  2. Path of your text File

For example

string logmsg;
 logmsg = "** " + DateTime.Now.ToString() + "||" + "User:" + UserName + "||" + " EventDesc: Login Attempt Failed";
                   l1.LogEntry(logmsg, Server.MapPath("LoginEvent.txt"));

Here the LoginEvnet.txt is the name of the text file where I am storing the log details.

logmsg-It is the message you have to track the or store in the log file

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文