我们正在尝试部署我们的项目,但我们无法让 elmah 在 wwwroot 之外创建 xml 日志。它当前正在记录到 inetpub{site}\wwwroot\App_Data,因为这是唯一可行的路径。我们希望将其记录到我们的 inetpub{site}\logs 文件夹中。有什么想法让它发挥作用吗?我们已经尝试过 ..\ 和 ../ 文件夹路径,但它们似乎不起作用。
ELMAH logPath 只能在 Web.config 中配置,可以是虚拟路径(如果以“~/”开头)或绝对文件系统路径。 Web.config 中 ELMAH logPath 的默认配置为:
<elmah>
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/Elmah.Errors" />
但是有一个解决方法,如何以编程方式设置 ELMAH logPath:
public class MvcApplication : HttpApplication
{
private static string _elmahDirectory;
private static readonly FieldInfo ElmahLogPathField = typeof(XmlFileErrorLog).GetField("_logPath", BindingFlags.NonPublic | BindingFlags.Instance);
protected void Application_Start()
{
// Assign your path here
_elmahDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
...
}
protected void Application_BeginRequest()
{
var xmlFileErrorLog = (XmlFileErrorLog)Elmah.ErrorLog.GetDefault(HttpContext.Current);
ElmahLogPathField.SetValue(xmlFileErrorLog, _elmahDirectory);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)