Skip to content

o14547/NLog.LiteDB

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NLog.LiteDb

NLog target for the LiteDB database

nlog-litedb MyGet Build Status

##Configuration Syntax

<extensions>
  <add assembly="NLog.LiteDB"/>
</extensions>
<targets>
    <target name="liteDB" 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>
</targets>
<rules>
  <logger name="*" minlevel="Trace" writeTo="liteDB" />
</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 - Connection string. When provided, it overrides the values specified in connectionName.

###Collection Options collectionName - The name of the LiteDB collection to write logs to.

###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="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>

###NLog.config target (LiteDB journal turned off)

    <target name="liteDB" 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"
      }
    }
}

About

NLog target for the LiteDB database

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%