log4net - 每个用户日志记录

发布于 2024-08-12 08:31:26 字数 347 浏览 4 评论 0原文

请帮助我使用 log4net 进行此查询。

我在我的应用程序中使用 log4net。我在配置 log4net 以在用户级别记录错误时遇到问题。

也就是说,如果用户 X 登录,我喜欢创建文件名 X,并且用户 X 的所有错误都应该写入 X.log 中。同样,如果Y用户登录日志文件的名称应该是Y.log,最需要注意的是,他们可以同时登录。

我尝试了创建日志文件,其名称将在用户登录后动态框定。但是这里出现问题,如果他们不同时使用该应用程序,则会使用正确的名称创建日志文件并按预期写入,但是如果两个用户都有活动会话,则仅为第一个登录的用户创建日志文件,并且第二个用户的错误已记录在为第一个用户创建的日志文件中。

请帮助我。

Please help me with this query in using log4net.

I am using log4net in mhy we application. I am facing issues in configuring log4net to log errors at user level.

That is, If user X logs in, I like to create file name X and all error for user X should be written in X.log. Siilarly if Y user logs in the log file should be in name of Y.log and the most important point to note is, they could log in concurrently.

I tried the luck by creating log files whose name would be framed dynamically as soon as the user logs in. But issue here, if they are not using the application at the same time, the log files are creeated with correct name and writing as expected, but if both users have active sessions, log file is created only for user who FIRST logged in and error of second user has been recorded in log file that is created for FIRST user.

Please help me in this.

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

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

发布评论

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

评论(1

靑春怀旧 2024-08-19 08:31:26

必须有一个更好的解决方案,但是您可以从代码中更改 log4net 配置,甚至可以决定要加载哪个配置文件 - 因此您可以在代码中完成此操作,这不如编辑 XML 文件那么好。

因此,您需要做的(强烈不推荐)是在每次调用记录器静态类时创建 log4net 配置,并根据调用用户执行所需的操作。

又来了..感觉不太对劲!

(而且它可能会表现得很差)。

另一个更好解决方案是使用用户列将所有内容记录到数据库(log4net支持它),然后从数据库生成日志....

There has to be a better solution from this one, but you can change log4net configuration from code and even decide which config file to load - so you can do it in code, which is not as nice as editing an XML file.

so what you need to do, which is highly not recommended, is to create log4net configuration each time you call the logger static class, and do what needed based on the calling user.

again.. it doesn't feel right !

(and it will probably perform poorly).

another BETTER solution is to log everything to database (log4net supports it), with a user column, and then produce the logs from db....

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