如何在Web配置文件中设置日志根目录 [英] How to set log root in web config file

查看:220
本文介绍了如何在Web配置文件中设置日志根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net应用程序,我在其中为方法中发生的任何异常写日志。



我的应用程序LOcatio是



D:\ MyTjectes



但我在应用程序旁边有日志目录



D:\ MyProjects \ Logs



我在Web Config中设置了错误日志路径,如下所示 -





< appsettings>

< add key =ErrorLogvalue =D:\ MyProjects\logs/> ;





工作正常但我在Plesk服务器上托管应用程序



然后如何在服务器上设置目录LOcation



PLease建议



什么我试过了:



我已在本地服务器上添加(在我的系统上)



< appsettings>

< add key =ErrorLogvalue =D:\ MyProjects\logs/>





但是我想在服务器上设置上面的设置 -

那么怎么做。

I have an asp.net application in which I am writing log for any exception occurs in methods.

My Application LOcatio is

D:\MyProjectes

But I have log directory in side the application

D:\MyProjects\Logs

I have set Error Log Path in Web Config like below--


<appsettings>
<add key="ErrorLog" value="D:\MyProjects\logs" />


Its Working Fine but When I have hosted application on Plesk Server

Then How to set the Directory LOcation on server

PLease Suggest

What I have tried:

I have Added on Local Server (On MY System)

<appsettings>
<add key="ErrorLog" value="D:\MyProjects\logs" />


But I want to set above setting on server--
then how to do that.

推荐答案

您将不得不询问托管您网站的公司。您需要授予写入文件夹的权限,然后您将需要该文件夹的路径。
You will have to ask the company that is hosting your site. You'll need permissions granted to write to a folder and then you'll need the path of that folder.


更改您的代码以支持虚拟文件夹而不是硬编码路径。因此,使用〜/ logs表示站点根目录中的logs文件夹而不是d:\ myprojects\logs,您可以使用

将该值映射到文件夹

Change your code to support virtual folders rather than hard-coded paths. So use "~/logs" to represent the "logs" folder in the root of your site rather than "d:\myprojects\logs" and you can map that value to a folder using

string logFolder = Server.MapPath("~/logs")





这样,无论你使用什么服务器,它都可以工作,因为MapPath将为你计算绝对文件夹路径。您可能最好将此文件夹存储在App_Data中,以便〜/ App_Data / logs



That way it will work no matter what server you put it on as MapPath will work out the absolute folder path for you. You're probably better storing this folder in App_Data as well so "~/App_Data/logs"


这篇关于如何在Web配置文件中设置日志根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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