Giter Club home page Giter Club logo

nlog.litedb's Introduction

NLog.LiteDb

Note - there is an experimental update in the FinalLiteDB4.x branch. Current plan is to migrate this to master as the last version supporting LiteDB 4.x versions. Test the latest version and open up any 'issues' you have with it. Migration, and the introduction of a new project targeting LiteDB 5.x support is scheduled for early 2021.

NLog target for the LiteDB database

Build status

Configuration Syntax

Examples below for the 4 connection string types:

  <targets>
    <!-- Legacy Target still supported-->
      <target name="legacy" xsi:type="liteDBTarget"
              connectionString="filename=NLog.db"
              collectionName="DefaultLog">
        <property name="ThreadID" layout="${threadid}" bsonType="Int32" />
        <property name="ThreadName" layout="${threadname}" />
        <property name="ProcessID" layout="${processid}" bsonType="Int32"  />
        <property name="ProcessName" layout="${processname:fullName=true}" />
        <property name="UserName" layout="${windows-identity}" />
     </target>
    <target name="special" xsi:type="liteDBTarget"
            connectionString="special={MyDocuments}\testApp\NLog.db"
            collectionName="DefaultLog" IsJournaling="false">
      <property name="ThreadID" layout="${threadid}" bsonType="Int32" />
      <property name="ThreadName" layout="${threadname}" />
      <property name="ProcessID" layout="${processid}" bsonType="Int32"  />
      <property name="ProcessName" layout="${processname:fullName=true}" />
      <property name="UserName" layout="${windows-identity}" />
    </target>
    <target name="path" xsi:type="liteDBTarget"
        connectionString="path=c:\temp\testApp\NLog.db"
        collectionName="DefaultLog" IsJournaling="false">
      <property name="ThreadID" layout="${threadid}" bsonType="Int32" />
      <property name="ThreadName" layout="${threadname}" />
      <property name="ProcessID" layout="${processid}" bsonType="Int32"  />
      <property name="ProcessName" layout="${processname:fullName=true}" />
      <property name="UserName" layout="${windows-identity}" />
    </target>
    <target name="file" xsi:type="liteDBTarget"
    connectionString="file=NLog.db"
    collectionName="DefaultLog" IsJournaling="false">
      <property name="ThreadID" layout="${threadid}" bsonType="Int32" />
      <property name="ThreadName" layout="${threadname}" />
      <property name="ProcessID" layout="${processid}" bsonType="Int32"  />
      <property name="ProcessName" layout="${processname:fullName=true}" />
      <property name="UserName" layout="${windows-identity}" />
    </target>
  </targets>

  <rules>
    <logger name="*" minlevel="Trace" maxlevel="Debug" writeTo="special" />
    <logger name="*" minlevel="Info" maxlevel="Warn" writeTo="path" />
    <logger name="*" minlevel="Error" maxlevel="Fatal" writeTo="file" />
  </rules>

Parameters

General Options

name - Name of the target.

Connection Options

connectionName - The name of the connection string to get from the config file.

connectionString - 4 connection string types are permitted.

  • Special - this allows for the connection string to utilize special folders - Refer to Microsoft documentation on Environment.SpecialFolder Enum for a full list. They are case sensitive.
  • Path - as this suggests - a file path.
  • File - just a base filename.
  • Legacy - for backwards compatiblity.

Collection Options

collectionName - The name of the LiteDB collection to write logs to.
IsJournaling - Journaling is enabled by default. Specify IsJournaling="false" to disable LiteDB journaling.

Document Options

includeDefaults - Specifies if the default document is created when writing to the collection. Defaults to true.

field - Specifies a root level document field. There can be multiple fields specified.

property - Specifies a dictionary property on the Properties field. There can be multiple properties specified.

Examples

Default Configuration with Extra Properties

NLog.config target

    <target name="liteDB" xsi:type="liteDBTarget"
            connectionString="file=NLog.db"
            collectionName="DefaultLog">        
      <property name="ThreadID" layout="${threadid}" bsonType="Int32" />
      <property name="ThreadName" layout="${threadname}" />
      <property name="ProcessID" layout="${processid}" bsonType="Int32"  />
      <property name="ProcessName" layout="${processname:fullName=true}" />
      <property name="UserName" layout="${windows-identity}" />
    </target>

NLog.config target (LiteDB journal turned off)

    <target name="liteDB" xsi:type="liteDBTarget"
            connectionString="file=NLog.db"
            collectionName="DefaultLog" IsJournaling="false">        
      <property name="ThreadID" layout="${threadid}" bsonType="Int32" />
      <property name="ThreadName" layout="${threadname}" />
      <property name="ProcessID" layout="${processid}" bsonType="Int32"  />
      <property name="ProcessName" layout="${processname:fullName=true}" />
      <property name="UserName" layout="${windows-identity}" />
    </target>

or

    <target name="legacy" xsi:type="liteDBTarget"
            connectionString="filename=NLog.db;journal=false"
            collectionName="DefaultLog">        
      <property name="ThreadID" layout="${threadid}" bsonType="Int32" />
      <property name="ThreadName" layout="${threadname}" />
      <property name="ProcessID" layout="${processid}" bsonType="Int32"  />
      <property name="ProcessName" layout="${processname:fullName=true}" />
      <property name="UserName" layout="${windows-identity}" />
    </target>

Default Output JSON

{
    "_id":{"$oid":"58aa0e644a8392ac98bb4812"},
    "Date":{"$date":"2017-02-19T21:30:12.4760000Z"},
    "Level":"Error",
    "Logger":"NLog.LiteDB.Specs.IntegrationTests.IntegrationTests",
    "Message":"Test Log Message",
    "Exception":
    {
      "Message":"Test Exception",
      "BaseMessage":"Inner Exception",
      "Text":"System.Exception: Test Exception ---> System.Exception: Inner Exception\r\n   --- End of inner exception stack trace ---",
      "Type":"System.Exception",
      "Source":null
    },
      "Properties":
      {
        "ThreadID":"10",
        "ProcessID":"44184",
        "ProcessName":"-Information about process here ",
        "UserName":"MachineName\\user"
      }
    }
}

nlog.litedb's People

Contributors

cccsdh avatar 304notmodified avatar

Stargazers

Jahongir avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.