wwwroot 之外的 Elmah logPath
我们正在尝试部署我们的项目,但无法让 elmah 在 wwwroot 之外创建 xml 日志。它当前正在记录到 inetpub{site}\wwwroot\App_Data,因为这是唯一可行的路径。我们希望将其记录到我们的 inetpub{site}\logs 文件夹中。有什么想法让它发挥作用吗?我们已经尝试过 ..\ 和 ../ 文件夹路径,但它们似乎不起作用。
We're trying to deploy our project but we can't get elmah to create the xml logs outsite the wwwroot. It's currently logging to inetpub{site}\wwwroot\App_Data because that's the only path that seemed to work. We would like to have it logging to our inetpub{site}\logs folder. Any ideas on getting this to work? We've already tried ..\ and ../ paths to the folder but they didn't seem to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以提供日志文件的绝对路径,但应确保配置为在 IIS 下运行 Web 应用程序的帐户具有对此文件夹的写入权限,以便它可以在其中创建和修改文件。
You could provide an absolute path to the log file but you should make sure that the account that is configured to run your web application under IIS has write permissions to this folder so that it can create and modify files inside.
正如 Darin 提到的,您是否确保运行 Web 应用程序的用户帐户有权访问您的日志文件夹。我认为相对路径应该没问题?还要确保该文件夹存在吗?
As Darin mentioned, did you ensure that the user account that the web application is running under has access to your logs folder. I would think a relative path should be fine though? Also make sure the folder exists?
如果您需要从代码中设置 logPath,而不是通过在配置文件中配置它,则可以这样做:
默认情况下,ELMAH 会读取您的 web.config 文件以找出要执行的
ErrorLog
实现创造。不过,您可以重写此机制来实现您自己的IServiceProvider
实现,并使用ServiceCenter.Current
属性注册返回实例的委托。这样的
IServiceProvider
实现如下所示:在应用程序启动期间,您可以执行以下操作:
这使您不必恢复到反射。
If you need to set the logPath from code instead of by configuring it in the config file, this is how to do it:
By default, ELMAH reads your web.config file to find out which
ErrorLog
implementation to create. You can however override this mechanism to implement your ownIServiceProvider
implementation and registering a delegate that returns an instance using theServiceCenter.Current
property.Such
IServiceProvider
implementation looks like this:And during application start, you can do the following:
This allows you prevents you from having to revert to reflection.
ELMAH logPath 只能在 Web.config 中配置,可以是虚拟路径(如果以“~/”开头)或绝对文件系统路径。 Web.config 中 ELMAH logPath 的默认配置是:
但是有一个解决方法如何以编程方式设置 ELMAH logPath:
ELMAH logPath can be configured in Web.config only and could be either virtual path (if started with "~/") or absolute file system path. The default configuration of ELMAH logPath in Web.config is:
But there is a workaround how to set ELMAH logPath programmatically: