Log4Net 输出到 Mongo
有谁有幸正确配置了这个吗?
- 在 MongoHQ 上创建了一个帐户
- 添加了一个新用户 到数据库
- 创建了一个名为
logs_net
的新集合 - 添加了 log4mongo-net 库
- 将配置添加到
web.config
并
<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?
- Created an account on MongoHQ
- Added a new user to the database
- Created a new Collection named
logs_net
- Added log4mongo-net library
- Added the configuration to the
web.config
<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();
toglobal.asax
underApplication_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议打开内部调试,这应该可以揭示出了什么问题。 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?
我由于不同的原因出现了相同的症状。我的 XML 日志记录配置错误。我是这样发现的。
1) 在创建记录器之前在代码中启用内部(不是 log4net)调试:
2) 运行代码并在 Visual Studio
Output
窗口中查看输出,并在中选择
下拉列表的输出。您应该能够看到 Appender 是如何构建的。Debug
>显示就我而言,数据库 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:
2) Run your code and see output in Visual Studio
Output
window withDebug
selected inShow 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.