gpt4 book ai didi

asp.net - Web 服务中的 Log4net

转载 作者:行者123 更新时间:2023-12-02 08:36:20 25 4
gpt4 key购买 nike

我的问题和

基本一样

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com