log4net的和system.data.sqlite [英] log4net and system.data.sqlite

查看:197
本文介绍了log4net的和system.data.sqlite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何设置log4net的使用system.data.sqlite提供一个很好的例子吗?

Does anyone know of a good example on how to set up log4net to use the system.data.sqlite provider?

我一直用它最近玩了,我想我拥有了一切工作。它使数据库并连接成功,写出来。然而,当我看看表数据时,它实际上从未犯下的日志。

I've been playing around with it lately and I thought I had it all working. It makes a successful connection to the database and "writes" it out. However, when I look at the table data, it never actually commits the log.

推荐答案

请确保您有以下引用set

Make sure you have the following references set:


  • log4net的(显然)

  • System.Data.SQLite(你可能会忘记这一个)

关闭Visual Studio中的项目,并重新打开.csproject(或同等VB)在文本编辑器,并查找参考部分。我的是这样的:

Close the project in Visual Studio and reopen the .csproject (or equivalent for VB) in a text editor, and look for the references section. Mine looks like this:

<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\..\..\..\externals\log4net-1.2.10\bin\net\2.0\release\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
  <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\..\..\..\externals\sqlite.net\System.Data.SQLite.dll</HintPath>
</Reference>



注意SQLite的参考。在这种情况下,你需要这样的文字: System.Data.SQLite,版本= 1.0.65.0,文化=中性公钥= db937bc2d44ff139 这是大会的全称它承载在ADO.net兼容SQL连接类,实际上什么log4net的有依赖的。

Notice the reference for SQLite. In this case you need this text: System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139 This is the full name of the assembly which hosts the ADO.net compatible sql connection classes which is actually what log4net has a dependency on.

重新打开在Visual Studio项目中,请确保您有config文件并打开它在XML文本编辑器。这将是更容易贴我的配置文件在这里比解释一切。 。在configSections XML节点,请注意,你要在这里使用的程序集名称

Reopen your project in Visual Studio, make sure you have .config file and open it in the XML text editor. It is going to be easier to paste my config file in here than explain everything. Notice that you are going to use the assembly name here.

将这个:

    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />



作为配置的直接XML childnode,把这个XML部分:

As a direct XML childnode of configuration, put this XML section:

<log4net>
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
        </layout>
    </appender>
    <appender name="sqlite" type="log4net.Appender.AdoNetAppender">
        <bufferSize value="100" />
        <connectionType value="System.Data.SQLite.SQLiteConnection, System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
        <connectionString value="Data Source=log4net.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>
    <root>
        <level value="ALL" />
        <appender-ref ref="ConsoleAppender" />
        <appender-ref ref="sqlite" />
    </root>
</log4net>



当你必须确保你指定的sqlite的数据库文件预存在于最后一步指定的位置。这样做的一种方法是创建该数据库并附加它作为资源被复制到输出文件夹。确保它具有相同的名称你指定的内容(在这种情况下 log4net.db

这篇关于log4net的和system.data.sqlite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆