嗨,我正在尝试为我的实时网站编写日志并且我的路径有问题,我需要使用方法 Server.MapPath 但我需要在我的 web.config 中完成它。
我该怎么办?
文件值保存路径,但我需要在其上设置一个 Server.MapPath。
<log4net>
<add key="LogFilePath1" value="../Logs/CurrentLog" id="FP1"/>
<add key="LogFilePath2" value="../Logs/CurrentLog.txt" id="FP2" />
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="../Logs/CurrentLog"/>
<appendToFile value="true"/>
<rollingStyle value="Size"/>
<maxSizeRollBackups value="10"/>
<maximumFileSize value="10000"/>
<staticLogFileName value="true"/>
<filter type="log4net.Filter.LevelRangeFilter">
<acceptOnMatch value="true"/>
<levelMin value="INFO"/>
<levelMax value="FATAL"/>
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5level %date [%thread] %-22.22c{1} - %m%n"/>
</layout>
</appender>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="../Logs/Log.txt"/>
<appendToFile value="true"/>
<layout type="log4net.Layout.PatternLayout">
<header value="**"/>
<footer value="**"/>
<conversionPattern value="%newline%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="LogFileAppender"/>
<appender-ref ref="ConsoleAppender"/>
<appender-ref ref="RollingFileAppender"/>
</root>
<logger name="ConsoleApp.LoggingExample">
<level value="ERROR"/>
<appender-ref ref="EventLogAppender"/>
</logger>
记录器代码 C#:
public class Logger
{
protected static readonly ILog logger = LogManager.GetLogger(typeof(Logger));
public void logError(string message, Exception ex)
{
HttpContext.Current.Server.MapPath(Convert.ToString(ConfigurationManager.AppSettings["LogFilePath1"]));
HttpContext.Current.Server.MapPath(Convert.ToString(ConfigurationManager.AppSettings["LogFilePath2"]));
log4net.Config.XmlConfigurator.Configure();
logger.Error(message + ex);
}
public void logInfo(string message)
{
HttpContext.Current.Server.MapPath(Convert.ToString(ConfigurationManager.AppSettings["LogFilePath1"]));
HttpContext.Current.Server.MapPath(Convert.ToString(ConfigurationManager.AppSettings["LogFilePath2"]));
log4net.Config.XmlConfigurator.Configure();
logger.Info(message);
}
}
我已将 C# 代码添加到 Server.MapPath 的键中,我只是在努力调用文件值中的键 =