使用SQLite的Log4Net正在抛出格式异常

时间:2012-11-06 02:04:31

标签: c# sqlite logging

我正在尝试使用Log4Net并将我的消息记录到本地SQLite DB。但是,当我运行应用程序时,log4net.Config.XmlConfigurator.Configure();

中会抛出格式异常

这是我的配置文件:

<log4net>

<appender name="LogFileAppender" type="log4net.Appender.FileAppender" >
  <file value="log-file.txt" />
  <appendToFile value="true" />

  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%-5level] - %message%newline" />
  </layout>
</appender>

<appender name="DebugAppender" type="log4net.Appender.DebugAppender">
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%-5level] - %message%newline" />
  </layout>
</appender>


<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
  <bufferSize value="0" />
  <connectionType value="System.Data.SQLite.SQLiteConnection, System.Data.SQLite, Version=1.0.77.0" />
  <connectionString value="Data Source=.\kapiti.db;Version=3;" />
  <commandText value="INSERT INTO Log (Date, Level, Logger, Message) VALUES (@Date, @Level, @Logger, @Message)" />
  <parameter>
    <parameterName value="@Date" />
    <dbType value="DateTime" />
    <layout type="log4net.Layout.RawTimeStampLayout" />
  </parameter>
  <parameter>
    <parameterName value="@Level" />
    <dbType value="String" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%level" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@Logger" />
    <dbType value="String" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%logger" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@Message" />
    <dbType value="String" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%message" />
    </layout>
  </parameter>
</appender>

<!-- Setup the root category, add the appenders
       and set the default level -->
<root>
  <level value="DEBUG" />
  <appender-ref ref="DebugAppender" />
  <appender-ref ref="LogFileAppender" />
  <appender-ref ref="AdoNetAppender" />
</root>

表是这样创建的,并且具有以下模式:

DROP TABLE IF EXISTS Log;
CREATE TABLE Log (
    LogId     INTEGER PRIMARY KEY,
    Date      DATETIME NOT NULL,
    Level     VARCHAR(50) NOT NULL,
    Logger    VARCHAR(255) NOT NULL,
    Message   TEXT DEFAULT NULL
    RowVersion INTEGER DEFAULT 1
);

CREATE TRIGGER Log_rowversion_trigger AFTER UPDATE ON Log 
BEGIN
UPDATE Log SET RowVersion = new.RowVersion + 1  WHERE Id = new.Id;
END;

如果你能看到我犯错误的地方,请告诉我,我一整天都被困在这里。

谢谢 RF

STACK TRACE:

mscorlib.dll!long.Parse(string s = "DateTime", System.Globalization.NumberStyles style = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign, System.IFormatProvider provider = {System.Globalization.NumberFormatInfo}) + 0x1a bytes 
mscorlib.dll!System.Convert.ToInt64(string value = "DateTime", System.IFormatProvider provider = {}) + 0x13 bytes   
mscorlib.dll!string.System.IConvertible.ToInt64(System.IFormatProvider provider = {}) + 0x7 bytes   
mscorlib.dll!System.Convert.DefaultToType(System.IConvertible value = "DateTime", System.Type targetType = {Name = "Int64" FullName = "System.Int64"}, System.IFormatProvider provider = {}) + 0xe5 bytes   
mscorlib.dll!string.System.IConvertible.ToType(System.Type type = {Name = "Int64" FullName = "System.Int64"}, System.IFormatProvider provider = {}) 
mscorlib.dll!System.Convert.ChangeType(object value = "DateTime", System.Type conversionType = {Name = "Int64" FullName = "System.Int64"}, System.IFormatProvider provider = {}) + 0x51 bytes   
log4net.dll!log4net.Util.OptionConverter.ParseEnum(System.Type enumType = {Name = "DbType" FullName = "System.Data.DbType"}, string value = "DateTime", bool ignoreCase = true) + 0x4d bytes    
log4net.dll!log4net.Util.OptionConverter.ConvertStringTo(System.Type target = {Name = "DbType" FullName = "System.Data.DbType"}, string txt = "DateTime") + 0x5d bytes  
log4net.dll!log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(System.Type type = {Name = "DbType" FullName = "System.Data.DbType"}, string value = "DateTime") + 0x41 bytes 
log4net.dll!log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(System.Xml.XmlElement element = {System.Xml.XmlElement}, object target = {log4net.Appender.AdoNetAppenderParameter}) + 0x282 bytes   
log4net.dll!log4net.Repository.Hierarchy.XmlHierarchyConfigurator.CreateObjectFromXml(System.Xml.XmlElement element = {System.Xml.XmlElement}, System.Type defaultTargetType = {Name = "AdoNetAppenderParameter" FullName = "log4net.Appender.AdoNetAppenderParameter"}, System.Type typeConstraint = {Name = "AdoNetAppenderParameter" FullName = "log4net.Appender.AdoNetAppenderParameter"}) + 0x13a bytes   
log4net.dll!log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(System.Xml.XmlElement element = {System.Xml.XmlElement}, object target = {log4net.Appender.AdoNetAppender}) + 0x525 bytes    
log4net.dll!log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(System.Xml.XmlElement appenderElement = {System.Xml.XmlElement}) + 0x170 bytes  
log4net.dll!log4net.Repository.Hierarchy.XmlHierarchyConfigurator.FindAppenderByReference(System.Xml.XmlElement appenderRef = {System.Xml.XmlElement}) + 0xb1 bytes 
log4net.dll!log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseChildrenOfLoggerElement(System.Xml.XmlElement catElement = {System.Xml.XmlElement}, log4net.Repository.Hierarchy.Logger log = {log4net.Repository.Hierarchy.RootLogger}, bool isRoot = true) + 0x4a bytes    
log4net.dll!log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseRoot(System.Xml.XmlElement rootElement = {System.Xml.XmlElement}) + 0x1d bytes   
log4net.dll!log4net.Repository.Hierarchy.XmlHierarchyConfigurator.Configure(System.Xml.XmlElement element = {System.Xml.XmlElement}) + 0x1e1 bytes  
log4net.dll!log4net.Repository.Hierarchy.Hierarchy.XmlRepositoryConfigure(System.Xml.XmlElement element = {System.Xml.XmlElement}) + 0xe bytes  
log4net.dll!log4net.Repository.Hierarchy.Hierarchy.log4net.Repository.IXmlRepositoryConfigurator.Configure(System.Xml.XmlElement element = {System.Xml.XmlElement}) + 0x7 bytes 
log4net.dll!log4net.Config.XmlConfigurator.ConfigureFromXml(log4net.Repository.ILoggerRepository repository = {log4net.Repository.Hierarchy.Hierarchy}, System.Xml.XmlElement element = {System.Xml.XmlElement}) + 0x7a bytes   
log4net.dll!log4net.Config.XmlConfigurator.Configure(log4net.Repository.ILoggerRepository repository = {log4net.Repository.Hierarchy.Hierarchy}, System.IO.Stream configStream = {System.IO.FileStream}) + 0xbb bytes   
log4net.dll!log4net.Config.XmlConfigurator.Configure(log4net.Repository.ILoggerRepository repository = {log4net.Repository.Hierarchy.Hierarchy}, System.IO.FileInfo configFile = {\Program Files\AlliedPetroleum.Client\AlliedPetroleum.Client.exe.config}) + 0xa7 bytes    
log4net.dll!log4net.Config.XmlConfigurator.Configure(log4net.Repository.ILoggerRepository repository = {log4net.Repository.Hierarchy.Hierarchy}) + 0x52 bytes   
  

log4net.dll!log4net.Config.XmlConfigurator.Configure()+ 0xf bytes AlliedPetroleum.Client.exe!AlliedPetroleum.Client.Program.Main()第47行+ 0x5字节C#

0 个答案:

没有答案