log4net 在 IIS7 上部署时不会创建日志文件

log4net doesn#39;t create log file when deployed on IIS7(log4net 在 IIS7 上部署时不会创建日志文件)
本文介绍了log4net 在 IIS7 上部署时不会创建日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家早上好,

我有一个 log4net 问题,在我开发时不存在本地机器,但是一旦我将应用程序部署到服务器,log4net 就停止工作了.

I have a log4net issue that didn't exist when I was developing on my local machine, but once I deployed the application to a server, log4net stopped working.

这是服务器配置:-Windows XP SP3-IIS 7-framework .Net v4

This is the server configuration : -Windows XP SP3 -IIS 7 -framework .Net v4

这是网站web.config中的log4net配置:

This is the log4net configuration in the web.config of the website:

<configuration>
      <log4net>
        <root>
          <level value="DEBUG" />
          <appender-ref ref="LogFileAppender" />
        </root>
        <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
          <param name="File" value="log.txt" />
          <param name="AppendToFile" value="true" />
          <rollingStyle value="Size" />
          <maxSizeRollBackups value="10" />
          <maximumFileSize value="30MB" />
          <staticLogFileName value="false" />
          <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" />
          </layout>
        </appender>
      </log4net>
    </configuration>

我还有一个类库,这是它的 App.config 文件:

I also have a class library and this is its App.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
  </configSections>
  <log4net>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="LogFileAppender" />
    </root>
    <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
      <param name="File" value="log.txt" />
      <param name="AppendToFile" value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="30MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" />
      </layout>
    </appender>
  </log4net>
</configuration>

这就是我在每个类上调用日志函数的方式:

This is how I call the log function on every class:

private static readonly ILog log = LogManager.GetLogger(typeof(AppDomain));

...这就是我所说的:

...and this is how i call it :

log.Error("
	=>" + ex.GetBaseException().Message + "

" + " @ " + Environment.StackTrace);

推荐答案

可能是您没有写入文件'log.txt'的权限.

It could be that you do not have permissions to write to the file 'log.txt'.

我不知道当前目录是什么,但它不太可能是 IIS 可以写入的位置.

I don't know what the current directory would be but it's unlikely to be somewhere IIS can write to.

您需要在某处创建一个文件夹并授予 IIS 写入权限,我知道您需要授予对 IIS_IUSRS 组的访问权限,然后指定该文件的绝对路径.例如

You need to create a folder somewhere and grant access for IIS to write to it, I understand you need to grant access to the IIS_IUSRS group and then specify the absolute path to that file. e.g.

<param name="File" value="D:Logslog.txt" />

..使用您首选位置的路径.

..using the path to your preferred location.

这篇关于log4net 在 IIS7 上部署时不会创建日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)