Log4Net 输出到 Mongo

发布于 2024-12-12 05:45:26 字数 1480 浏览 0 评论 0原文

有谁有幸正确配置了这个吗?

<log4net>
  <appender name="MongoAppender" type="log4net.Appender.MongoDBAppender, log4mongo-net">
     <!-- MongoDB connection options -->
     <host value="staff.mongohq.com" />
     <port value="10048" />
     <databaseName value="d1741d63-46b1-4a44-9c21-8a85cecae45b" />
     <collectionName value="logs_net" />
     <userName value="balexandre" />
     <password value="myPassWorD" />
  </appender>

  • 添加log4net.Config.XmlConfigurator.Configure();Application_Start() 下的 global.asax

并添加一些信息:

ILog logger = LogManager.GetLogger(this.GetType());
logger.Info("MainController Initialize test");

而且...我可以无法登录 MongoDB,有什么帮助吗?

顺便说一句,数据库名称不正确,密码也不正确,如果我使用 log4net.Appender.RollingFileAppender效果很好。

Does anyone had the luck to have this configured correctly?

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

and

<log4net>
  <appender name="MongoAppender" type="log4net.Appender.MongoDBAppender, log4mongo-net">
     <!-- MongoDB connection options -->
     <host value="staff.mongohq.com" />
     <port value="10048" />
     <databaseName value="d1741d63-46b1-4a44-9c21-8a85cecae45b" />
     <collectionName value="logs_net" />
     <userName value="balexandre" />
     <password value="myPassWorD" />
  </appender>

  • Added log4net.Config.XmlConfigurator.Configure(); to global.asax under Application_Start()

and added some info:

ILog logger = LogManager.GetLogger(this.GetType());
logger.Info("MainController Initialize test");

And... I can't get logs into MongoDB, any help?

By the way, the Database name is not the correct one, neither the password, and if I use log4net.Appender.RollingFileAppender it works great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

好多鱼好多余 2024-12-19 05:45:26

我建议打开内部调试,这应该可以揭示出了什么问题。 log4mongo 程序集很可能未正确加载。您确定它已复制(包含所有依赖项)到 bin 文件夹吗?

I suggest turning on internal debugging, this should reveal what is going wrong. It is quite possible that the log4mongo assembly is not loaded correctly. Are you sure it is copied (with all dependencies) to the bin folder?

痴梦一场 2024-12-19 05:45:26

我由于不同的原因出现了相同的症状。我的 XML 日志记录配置错误。我是这样发现的。

1) 在创建记录器之前在代码中启用内部(不是 log4net)调试:

log4net.Util.LogLog.InternalDebugging = true;
...
XmlElement conf = ...
XmlConfigurator.Configure(conf);
var logger = LogManager.GetLogger(loggerName);

2) 运行代码并在 Visual Studio Output 窗口中查看输出,并在 中选择 Debug >显示下拉列表的输出。您应该能够看到 Appender 是如何构建的。

就我而言,数据库 url 是错误的 - 我以错误的格式指定了其他选项。

I had the same symptoms for a different reason. My XML logging configuration was wrong. Here is how I found out.

1) Enable internal (not log4net) debugging in the code before logger is created:

log4net.Util.LogLog.InternalDebugging = true;
...
XmlElement conf = ...
XmlConfigurator.Configure(conf);
var logger = LogManager.GetLogger(loggerName);

2) Run your code and see output in Visual Studio Output window with Debug selected in Show output from dropdown. You should be able to see how Appenders are constructed.

In my case database url was wrong - I specified additional options in a bad format.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文