我正在运行一个网站和一个 Windows 服务。我可以在运行时使用我制作的页面更改我的网站的日志级别,并且我想对我的 Windows 服务执行相同的操作(即:使用页面来监视我在服务)。
您有一些技巧和窍门可以实现这一目标吗?或者,每次我需要更详细地记录内容时,我是否应该辞职并上传新版本的 log4net 文件(此上传有点棘手且相当烦人)?
感谢您的想法,
[编辑]
不幸的是,这里列出的答案都不是针对我的问题的。我的方法是从机器 B 上运行的网站访问位于机器 A 上的服务的 log4net。因此,访问机器 A 的 Web 可能允许我更改机器 B 的服务线程的日志级别。
I am running a website and a windows service . I am able to change at runtime the level of log of my Website using a page I made, and I would like to do the same for my windows service( ie: using a page to monitor the different levels of Log I am using in the service).
Would you have some tips and tricks to achieve that? Or should I resign and upload a new version of the log4net file every time I need to log things a bit more in details (this upload is a bit tricky and quite annoying to do)?
thanks for your ideas,
[EDIT]
UNfortunately none of the answer listed here are aimed at my problem. Mine is to access the log4net from a service located on a Machine A from a WebSite running on a machine B. So that accessing the Web of MAchine A may allow me to change log level of service thread of Machine B.
发布评论
评论(3)
如果您的 Windows 服务使用 ConfigureAndWatch 您应该如果将配置文件放置在可通过网页访问的位置,则可以像使用您创建的页面编辑网站一样编辑配置文件。
您还必须更改在 Windows 服务中加载的配置文件的路径,但这应该是一个解决方案。
If your windows service is using ConfigureAndWatch you should be able to edit the config file just like you do for your website with that page you made if you place the configuration file in a place that is accessible via the web page.
You will also have to change the path to the configuration file you load in your windows service but this should be a solution.
您可以修改配置文件并让您的应用程序接受更改。诀窍是您不能使用 app.config/web.config 文件来执行此操作。否则,需要重新启动应用程序才能发生更改。这是一个 SO 问题,有几个可能有效的答案:
.net 动态刷新 app.config< /a>
您还可以通过代码进行更改,如下所示:
http://weblogs.asp.net/psteele/archive/2010/05/03/tweaking-log4net-settings-programmatically.aspx
You can modify a config file and have your application pick up the changes. The trick is that you cannot use the app.config/web.config file to do so. Otherwise, it takes a reboot of your application before the changes will take place. Here is a SO question that has a couple answers that might work:
.net dynamically refresh app.config
You can also make changes through code like so:
http://weblogs.asp.net/psteele/archive/2010/05/03/tweaking-log4net-settings-programmatically.aspx
好的,只有我发现的东西,它连接我的服务和 Web 应用程序以访问数据库中的同一个表,并定期检查该表以更改 servizio 中的日志级别。
如果有人有更好的主意,我会洗耳恭听。
Ok only things I found, it to interface my service and Web Application to access the same table in the database, and make regular check to this table to change log level in servizio.
If someone has a better idea, I am all ears.