滚动Log4Net日志文件中的自定义文件名? [英] Custom filename in a rolling Log4Net logfile?

查看:457
本文介绍了滚动Log4Net日志文件中的自定义文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个ASP .Net应用程序,使用Log4Net可以在应用程序内记录详细信息-那里没有新内容-滚动日志文件名的格式通常为:

We have a ASP .Net application whereby we use Log4Net to log details within the app - nothing new there - and the rolling log filenames are in the usual format of:

rolling-log.txt 
rolling-log.txt.1
rolling-log.txt.2 etc.

应用程序的每个用户都添加到日志文件中,对于特定用户而言,很难读取日志文件,因此,我们希望以某种方式修改配置文件,以分别记录用户的日志详细信息,每次写入特定文件,例如

A each user of the application adds to the logfile, the logfile can be difficult to read for a specific user's case and so, we'd like to modify the config file somehow to record the user's log details individually, each writing to a specific file, e.g.

<applicationId>rolling-log.txt
<applicationId>rolling-log.txt.1
<applicationId>rolling-log.txt.2
etc.

每个用户的唯一应用ID在哪里,由五个数字组成,例如

where is each user's unique application Id, made up of a five digit number, e.g.

12345rolling-log.txt

是否有可能实现最佳方法的任何想法?

Any ideas on the best way to implement this, assuming that it's possible?

欢呼

布雷特(Brett)

推荐答案

查找log4net上下文属性...

look for log4net Context Properties...

在您的代码中:

log4net.GlobalContext.Properties["id"] = "12345";

然后

log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo("configPath"));

在log4net配置文件中:

in the log4net config file:

<file type="log4net.Util.PatternString"
            value="%property{id}rolling-log.txt" />

这篇关于滚动Log4Net日志文件中的自定义文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆