Unable to insert log records into MySQL database solution using log4net

Source: Internet
Author: User
Tags log4net

Write in front

It's all right. Under the study, the log file is written to the MySQL database, because the new company uses the database is also MySQL, the project needs to write log information to the database, there is no way to study the next. In the use of the process encountered a very painful problem. Finally solved, depressed for half a day. Make a record here so that you don't do it again.

Before writing this article, about the configuration information, you can refer to my article: log4net Log records two ways

Solutions

The problem is that I directly copy the log4net to the database log4net.config to use it in the project, of course, modify the connection string, the provider and other MySQL-related configuration. The configuration file is as follows:

<?XML version= "1.0" encoding= "Utf-8"?><Configuration>  <configsections>    < Sectionname= "Log4net"type= "log4net." Config.log4netconfigurationsectionhandler, log4net " />  </configsections>  <!--log4net Begin -  <log4net>    <Appendername= "Adonetappender_mysql"type= "log4net." Appender.adonetappender ">      <buffersizevalue= "1" />      <ConnectionTypevalue= "MySql.Data.MySqlClient.MySqlConnection, mysql.data" />      <connectionStringvalue= "Server=127.0.0.1;user id=root;pwd=root;port=3306;pooling=true;database=cowork_db"ProviderName= "MySql.Data.MySqlClient;" />      <CommandTextvalue= "INSERT into Coworkdocument_log (log_date,log_thread,log_level,log_logger,log_message,log_exception) VALUES ( @log_date, @log_Thread, @log_level, @log_Logger, @log_Message, @log_Exception) " />      <parameter>        <parameternamevalue= "@log_date" />        <DbTypevalue= "DateTime" />        <Layouttype= "log4net." Layout.rawtimestamplayout " />      </parameter>      <parameter>        <parameternamevalue= "@log_Thread" />        <DbTypevalue= "String" />        <sizevalue= "+" />        <Layouttype= "log4net." Layout.patternlayout ">          <Conversionpatternvalue= "%thread" />        </Layout>      </parameter>      <parameter>        <parameternamevalue= "@log_Level" />        <DbTypevalue= "String" />        <sizevalue= "+" />        <Layouttype= "log4net." Layout.patternlayout ">          <Conversionpatternvalue= "%level" />        </Layout>      </parameter>      <parameter>        <parameternamevalue= "@log_Logger" />        <DbTypevalue= "String" />        <sizevalue= "+" />        <Layouttype= "log4net." Layout.patternlayout ">          <Conversionpatternvalue= "%logger" />        </Layout>      </parameter>      <parameter>        <parameternamevalue= "@log_Message" />        <DbTypevalue= "String" />        <sizevalue= "+" />        <Layouttype= "log4net." Layout.patternlayout ">          <Conversionpatternvalue= "%message" />        </Layout>      </parameter>      <parameter>        <parameternamevalue= "@log_Exception" />        <DbTypevalue= "String" />        <sizevalue= "4000" />        <Layouttype= "log4net." Layout.exceptionlayout " />      </parameter>    </Appender>    <!--setup The root category, add the Appenders and set the default level -    <Root>      < Levelvalue= "All"/>      <Appender-refref= "Adonetappender_mysql"/>    </Root>  </log4net>  <!--log4net End -</Configuration>

Get a long time, do not know where the problem is, is not inserted into the data, no words died, finally, a flash, the SQL statement is modified as follows:

1 INSERT into Coworkdocument_log (log_date,log_thread,log_level,log_logger,log_message,log_exception) VALUES (@log_date, @log_Thread, @log_level, @log_Logger, @log_Message, @log_Exception)

Compared to the previous article's SQL Server configuration file you will find that I removed the field [], it is estimated that MySQL does not support the syntax bar, after the removal, the problem can be resolved, not depressed?

Unable to insert log records into MySQL database solution using log4net

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.