ASP。Net用户活动跟踪数据库

时间:2021-03-20 12:41:58

This is about a simple yet efficient activity logging framework that I want to integrate with my existing ASP.Net based web-app (I've a LINQ-to-SQL based SQL DB as backend). I'm using something like a service-architecture to perform DB operations - that is invoke relevant LINQ operations. I've a service class for almost every entity (i.e. DB table) and it handles the CRUD operations.

这是一个简单而高效的活动日志记录框架,我想将它与我现有的ASP集成在一起。基于Net的web应用程序(我有一个基于linqto -SQL的SQL DB作为后端)。我正在使用类似于服务体系结构的东西来执行DB操作——即调用相关的LINQ操作。我有一个服务类用于几乎所有的实体(例如DB表),它处理CRUD操作。

In general, I need to track activities like - Mr.X added a new Item, My.Y searched on this filter, Mr.Z exported the result of Grid to an excel document, etc... and similar simple operation based logging (field-level logging is far for now)

一般来说,我需要跟踪活动,比如x先生添加了一个新项目,My。Y在这个过滤器上搜索,z先生将网格的结果导出到excel文档,等等……以及类似的基于操作的简单日志记录(目前还远未实现字段级日志记录)

So, here's what I've found in my two days of R&D on the SO, other forums and the web:

所以,这是我在So,其他论坛和网络上两天的研究发现:

Approach 1: Simple old way of using two tables: Activity (stores ALL the activities along with its actor) & ActivityType (lists types of activities). I've a service layer so either I can have a "ServieBase" class which taps ALL the CRUD events and logs the one in which I'm interested. Everything is handled from within the code.

方法1:使用两个表的简单旧方法:Activity(存储所有活动及其参与者)和ActivityType(列出活动类型)。我有一个服务层,所以我可以有一个“ServieBase”类,它可以访问所有CRUD事件并记录我感兴趣的事件。一切都是在代码中处理的。

Example: http://dotnetslackers.com/articles/aspnet/Tracking-User-Activity.aspx

例如:http://dotnetslackers.com/articles/aspnet/Tracking-User-Activity.aspx

Approach 2: Use database TRIGGERs to tap events at table level and then perform logging. This will be completely 'abstract' to the app. I've "LastModifiedBy" field in each table so I'll get the 'actor' data and I can do the logging but this might limit me to DB-operations & need me to track other app-activities separately. but if its worth I can consider it.

方法2:使用数据库触发器在表级点击事件,然后执行日志记录。这对应用程序来说是完全“抽象”的。我在每个表中都有“LastModifiedBy”字段,这样我就可以获得“actor”数据,我可以进行日志记录,但这可能限制我使用DB-operations,需要我单独跟踪其他应用程序活动。但如果值得,我可以考虑。

Approach 3: (conceptual, need more guidance)

方法3:(概念性的,需要更多的指导)

3.1 MVC approach - We're thinking of adopting MVC in future and I've found some efficient logging tricks in MVC like - (is ther anything like that for traditional L2S based web-app?)

3.1 MVC方法——我们正在考虑将来采用MVC,我在MVC中发现了一些高效的日志技巧,比如——(基于传统L2S的web应用还有类似的吗?)

Log User Activity on ASP.NET MVC Application Track user activity/actions for an asp.net mvc website?

在ASP上记录用户活动。NET MVC应用程序跟踪asp.net MVC网站的用户活动/操作?

3.2 Tracking Services I came across a 'tracking service' feature in windows - is there its web-equivalent?

3.2跟踪服务我在windows中发现了一个“跟踪服务”功能——它是否与网络相当?

http://msdn.microsoft.com/en-us/magazine/cc163466.aspx http://www.codeproject.com/KB/WF/WWF__Tracking_Service.aspx?msg=2879654

http://msdn.microsoft.com/en-us/magazine/cc163466.aspx http://www.codeproject.com/KB/WF/WWF__Tracking_Service.aspx?msg=2879654

3.3 Misc - Some other options which I came across but don't seem too convincing or I'd better say they do their work but not mine :-)

3.3 Misc——我遇到的一些其他选项,但似乎不太令人信服,或者我最好说他们是在做他们的工作,但不是我的:-)

Ref -

Ref -

http://learn.iis.net/page.aspx/480/sample-web-analytics-tracking-module/

http://learn.iis.net/page.aspx/480/sample-web-analytics-tracking-module/

SQL Profiler: https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-5054787.html http://technet.microsoft.com/en-us/library/cc966515.aspx

SQL分析器:https://web.archive.org/web/1/http:/ / articles.techrepublic % 2易康姆% 2易康姆/ 5100 - 10878 - _11 - 5054787. - html http://technet.microsoft.com/en-us/library/cc966515.aspx

So, what say? Any suggestions and new thoughts are welcome. For now, it seems I'd land somewhere between the first-two approaches because we want it to be easy in future to be able to add any extra activity to be logged.

所以,说什么?欢迎提出建议和新想法。现在看来,我将在前两种方法之间找到一个平衡点,因为我们希望将来能够轻松地添加任何额外的日志记录。

Thank you.

谢谢你!

2 个解决方案

#1


1  

Here's another item to add to your toolkit: Sql Server Change Tracking. But it won't do everything you're looking for here. You might take a look at the Command pattern. I would create an interface, ITrackedCommand, and then implement those as the commands that the user can perform. Then, each one is executed through a command dispatcher which automatically calls ITrackedCommand.Log. I think that will get you where you need to go.

下面是添加到工具包的另一个项目:Sql Server更改跟踪。但它不会做你想要的一切。您可以查看一下命令模式。我将创建一个接口ITrackedCommand,然后将其实现为用户可以执行的命令。然后,每个命令都通过一个命令分派器执行,该分派器自动调用ITrackedCommand.Log。我想这会让你到达你需要去的地方。

#2


1  

I ended up using among the first two approaches because they seem more simple and easier. Most of all they provide more control and allow to keep thing as flexible as required (i.e. its near to the actual backend coding which makes it more accessible)

我最后使用了前两种方法,因为它们看起来更简单、更容易。最重要的是,它们提供了更多的控制,并允许按照要求保持事物的灵活性(例如,它靠近实际的后端编码,使其更易于访问)

I'm marking it as there has been no other extensive reviews.

我标记它,因为没有其他广泛的评论。

Thank you.

谢谢你!

#1


1  

Here's another item to add to your toolkit: Sql Server Change Tracking. But it won't do everything you're looking for here. You might take a look at the Command pattern. I would create an interface, ITrackedCommand, and then implement those as the commands that the user can perform. Then, each one is executed through a command dispatcher which automatically calls ITrackedCommand.Log. I think that will get you where you need to go.

下面是添加到工具包的另一个项目:Sql Server更改跟踪。但它不会做你想要的一切。您可以查看一下命令模式。我将创建一个接口ITrackedCommand,然后将其实现为用户可以执行的命令。然后,每个命令都通过一个命令分派器执行,该分派器自动调用ITrackedCommand.Log。我想这会让你到达你需要去的地方。

#2


1  

I ended up using among the first two approaches because they seem more simple and easier. Most of all they provide more control and allow to keep thing as flexible as required (i.e. its near to the actual backend coding which makes it more accessible)

我最后使用了前两种方法,因为它们看起来更简单、更容易。最重要的是,它们提供了更多的控制,并允许按照要求保持事物的灵活性(例如,它靠近实际的后端编码,使其更易于访问)

I'm marking it as there has been no other extensive reviews.

我标记它,因为没有其他广泛的评论。

Thank you.

谢谢你!