它不再显示任何错误,但它也不会在MySQL数据库中插入任何内容。有任何想法吗?我用虚拟文本替换了我的登录信息。
修改
连接类型有错误。
log4net:ERROR [AdoNetAppender] ErrorCode: GenericFailure. Failed to load connection type [MySql.Data.MySqlClient.MySqlConnection, MySql.Data, Version=5.5.47, Culture=neutral, PublicKeyToken=c5687fc88969c44d]
System.IO.FileNotFoundException: Could not load file or assembly 'MySql.Data, Version=5.5.47, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified.
File name: 'MySql.Data, Version=5.5.47, Culture=neutral, PublicKeyToken=c5687fc88969c44d'
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Util.SystemInfo.GetTypeFromString(Assembly relativeAssembly, String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Util.SystemInfo.GetTypeFromString(String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Appender.AdoNetAppender.ResolveConnectionType()
这是我的App.config
档案
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<!-- appenders here -->
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="MySql.Data.MySqlClient.MySqlConnection, MySql.Data, Version=5.5.47, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
<connectionString value="Server=myhost;Database=mydb;UID=myuser;Password=mypassword" />
<commandText value="INSERT INTO mylog (date) VALUES (?date)" />
<parameter>
<parameterName value="date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
</appender>
<root>
<level value="Debug"/>
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="FileAppender" />
<appender-ref ref="RollingFileAppender" />
<appender-ref ref="ADONetAppender" />
<appender-ref ref="SmtpAppender" />
</root>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
</configuration>
答案 0 :(得分:1)
您在bin目录中缺少MySQL.Data dll或依赖项。可能的是,您的项目中没有直接引用,因此不会被复制。制作参考并确保将其复制到您的bin目录中。