我试图让Log4Net集成在.NET Core应用程序中运行,该应用程序将部署到AppEngine Flexible环境中。我的出发点是documentation中的示例代码。我的代码看起来像这样:
using log4net; // resolve Log4net
using log4net.Config; // resolve XmlConfigurator
using System.IO; // resolve FileInfo
using System.Reflection; // resolve Assembly
namespace Test
{
public class PlayWithStackdriverLog4net
{
public void Write()
{
log4net.Util.LogLog.InternalDebugging = true; // enable Log4net debugging
var xmlConfiguration = XmlConfigurator.Configure(LogManager.GetRepository(typeof(PlayWithStackdriverLog4net).Assembly), new FileInfo("log4net.xml"));
ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
log.Info("An exciting log entry!");
}
}
}
不幸的是,最终结果是我在Google云端控制台的“日志记录”窗格中看不到令人兴奋的日志条目!。我做错了什么?
一些评论:
1)文件log4net.xml几乎是documentation中的文件,除了我用自己的ID替换了PROJECT-ID。
2)Log4net调试输出表明它已成功读取log4net.xml:
log4net: log4net assembly [log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a]. (.NET Framework [.NET Core 4.6.26020.03] on Microsoft Windows 6.1.7601 S)
log4net: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository for assembly [Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]
log4net: Assembly [Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [Not supported on .NET Core]
log4net: Assembly [Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: Assembly [Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy]
log4net: configuring repository [log4net-default-repository] using file [log4net.xml]
log4net: configuring repository [log4net-default-repository] using stream
log4net: loading XML configuration
log4net: Configuring Repository [log4net-default-repository]
log4net: Configuration update mode [Merge].
log4net: Logger [root] Level string is [ALL].
log4net: Logger [root] level set to [name="ALL",value=-2147483648].
log4net: Loading Appender [CloudLogger] type: [Google.Cloud.Logging.Log4Net.GoogleStackdriverAppender,Google.Cloud.Logging.Log4Net]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%-4timestamp [%thread] %-5level %logger %ndc - %message]
log4net: Converter [timestamp] Option [] Format [min=4,max=2147483647,leftAlign=True]
log4net: Converter [literal] Option [ [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [thread] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [] ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [level] Option [] Format [min=5,max=2147483647,leftAlign=True]
log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [logger] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [ndc] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: Setting Property [ProjectId] to String value [my-project-id-goes-here]
log4net: Setting Property [LogId] to String value [mySampleLog]
log4net: Created Appender [CloudLogger]
log4net: Adding appender named [CloudLogger] to logger [root].
log4net: Hierarchy Threshold []
3)如果我按照使用Google.Cloud.Logging.V2的Stackdriver Logging Client Libraries的示例,那么我可以找到我的“你好世界”#39;全局资源类型中的文本按预期方式。