如何为每个 log4net 记录器实例创建新文件?
我试图为每个线程创建一个不同的日志文件(线程正在处理一些站点处理)。本质上只是使用从正在处理的站点派生的名称来命名日志文件。
我了解 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您重新考虑您的日志记录策略,而不是与配置作斗争。 log4net 不是为每个线程/类的日志文件构建的。记录器是在启动时或第一次写入时创建的(取决于)。使用尾部日志文件阅读器(例如 Kiwi Log Viewer 或 Splunk),并过滤消息中的线程 ID 或记录器名称。
如果你把它们放在你的转换模式中......
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...