asp.net - Web 服务中的 Log4net

标签 asp.net service web log4net

我的问题和

基本一样

log4net only works when XmlConfigurator.Configure() is called

但是,我无法在那里发表评论,因为我没有任何声誉(刚刚注册)。

感谢任何有用的评论。 如果我在这里做错了什么,请指教。 非常感谢。伯恩德

更新: 感谢您的建设性提示。我已经取得了一些进展,因此将更详细地解释: 我在(VS 生成的 C# Web 服务)中使用 log4net。我确实在调试文件中获得了调试信息,但是在 VS (2012) 中我确实获得了每个日志记录调用的消息:

log4net:ERROR An exception ocurred while retreiving stack frame information.
System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
     bei log4net.Core.StackFrameItem..ctor(StackFrame frame)

我通过 XML 配置它:

<?xml version="1.0" encoding="utf-8" ?>
<log4net>  
  <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
    <file value="Logs/debug.log" />
    <encoding value="utf-8" />
    <appendToFile value="true" />
    <maximumFileSize value="10MB" />
    <maxSizeRollBackups value="2" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level (%class#%method:%line):%message%newline" />
    </layout>
  </appender>
  <root>
    <level value="DEBUG" />    
    <appender-ref ref="RollingFile" />
  </root>
</log4net>

我的网络服务是这样的:

public class ObjectInfo : IObjectInfo
{    
    private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);



    public void DoWork()        {
      Logging.LoggingUtil.InitializeLogging();
      log.Debug("Some message");
    }
}

希望这已经足够了。 LoggingUtil- 类基本上如下所示:

private const String Log4NetConfigurationFilePath = "log4net-config.xml"; //real path looks somewhat different
public static void InitializeLogging()
{    
  XmlConfigurator.Configure(new FileInfo(Log4NetConfigurationFilePath));     
}

我想知道,如果问题是在 Cassine 中无法找到堆栈跟踪,因为 Microsoft 不允许这样做以保护他们的 Web 服务实现?

最佳答案

LOG4NET-393 中所述, 当调用链中存在动态方法时会出现此错误。

他们声称在版本 > 1.2.12 中修复了这个错误。

关于asp.net - Web 服务中的 Log4net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20976670/

相关文章:

nginx 中应用程序的 SSL

asp.net - 在 App_Start 中初始化和播种 Identity 的 DbContext

c# - 在并发请求期间访问 session 值

linux - 仅当服务 A 存在时,Systemd 服务 B 才会在另一个服务 A 之后启动

android - StopService 或删除处理程序回调(电池消耗)

html - 如何将 html 音频播放器居中/居中到网页中间?

grails - Grails-客户端与服务器端模板

asp.net - Jquery隐藏字段

asp.net - 网站重写了所有 URL,但过了一段时间 404 全部

linux - 在 systemd 服务的 ExecStart 命令路径中使用变量