如何为每个 log4net 记录器实例创建新文件?

发布于 2024-09-25 14:32:26 字数 340 浏览 0 评论 0原文

我试图为每个线程创建一个不同的日志文件(线程正在处理一些站点处理)。本质上只是使用从正在处理的站点派生的名称来命名日志文件。

我了解 GlobalContext.properties 和 TheadContext.properties 的所有信息,但似乎都不适用于我想要做的事情。在几乎任何一种情况下,任何并发运行的线程都只使用当前输出文件作为其输出。我看到的唯一区别是,如果我使用 ThreadContext 设置属性,它会生成所有文件,但仅输出到一个文件,而使用 global 似乎只会生成一个文件,除非进程在不同时间启动。

我真正想做的是能够告诉文件仅在文件名中使用记录器对象的名称(用于实例化对象的名称),而不是使用这些属性。

I am trying to create a different log file for each thread (the threads are handling some site processing). Essentially just naming the log file with a name that is derived from the site that is being processed.

I know all about the GlobalContext.properties and also the TheadContext.properties and neither really seem to work for what I am trying to do. In pretty much either case any concurrently running threads just use whichever file is the current output file as their output. The only difference I have seen is that if I use the ThreadContext to set the property it makes all the files but only outputs to one, where using global it seems to only make the one file unless the processes start at different times.

What I would REALLY like to do is be able to tell the file to just use the name of the logger object (the name that is used in instantiating the object) in the file name instead of using these properties.

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

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

发布评论

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

评论(1

给妤﹃绝世温柔 2024-10-02 14:32:26

我建议您重新考虑您的日志记录策略,而不是与配置作斗争。 log4net 不是为每个线程/类的日志文件构建的。记录器是在启动时或第一次写入时创建的(取决于)。使用尾部日志文件阅读器(例如 Kiwi Log Viewer 或 Splunk),并过滤消息中的线程 ID 或记录器名称。

如果你把它们放在你的转换模式中......

<conversionPattern value="%date [%thread] %-5level %logger: %message%newline" />

Instead of fighting the configuration, I recommend that you rethink your logging strategy. log4net was not built for a log file per thread/class. Loggers are created at startup or on first write (depends). Use a tailing log file reader, like Kiwi Log Viewer or Splunk, and filter on the thread id or logger name in your messages.

If you put them in your conversion pattern...

<conversionPattern value="%date [%thread] %-5level %logger: %message%newline" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文