C# 应用程序中 log4net 附加到 mysql
我正在构建一个小型 C# Web 应用程序(用 mvc 编写)。 我需要将基本信息记录到数据库中。 我进行了研究,发现 log4net 相当广泛且流行。
我使用 mysql 作为我的下线数据库。 我找到了一些如何使用 log4net 登录 mysql 数据库的示例,但似乎不起作用,而且它们看起来都相当过时。
有人有这方面的代码示例吗?
非常感谢。
I am building a small c# web application (written in mvc).
I need to log basic info to a database.
I've researched and found log4net to be quite extensive and popular.
I'm using mysql as my underline database.
I found a few samples of how to log using log4net into mysql database, but non seem to work, and they all seem quite outdated.
Does anyone have a code sample for this?
Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您可以通过AdoNetAppender来实现此日志记录。看起来您可以配置连接类型(mysql、oracle、sqlserver 等)。
可以通过设置connectionType属性来指定连接类型(提供者)
以上摘自:
http://logging.apache.org/log4net/release/sdk /log4net.Appender.AdoNetAppender.html
我将尝试跟进一个示例配置,但我认为他们很好地解释了如何使用 sql server 数据库执行此操作,看起来就像您只需要更改 connectionString 和 connectionType 属性一样。
It seems to me that you can achieve this logging through the AdoNetAppender. It looks like you can configure the connection type (mysql, oracle, sqlserver etc).
The connection type (provider) can be specified by setting the connectionType property
The above was taken from:
http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppender.html
I'll try to follow up with an example config for this but I think they do a fair job of explaining how to do this with a sql server database and it seems like you would just need to change the connectionString and connectionType properties.