Skip to content

Nethereum/NethereumNlogSample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nethereum Nlog Sample

Logging trace requests example using nlog

image

Nethereum uses "Trace" to log requests and responses, so the configuration needs to be configured as such.

More info on setup Nlog can be found here: https://github.com/NLog/NLog/wiki/Getting-started-with-.NET-Core-2---Console-application#a-minimal-example

Example configuration file:

<?xml version="1.0" encoding="utf-8" ?>
<!-- XSD manual extracted from package NLog.Schema: https://www.nuget.org/packages/NLog.Schema-->
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xsi:schemaLocation="NLog NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogFile="c:\temp\console-example-internal.log"
      internalLogLevel="Trace" >

	<!-- the targets to write to -->
	<targets>
		<!-- write logs to file -->
		<target xsi:type="File" name="logfile" fileName="c:\temp\console-example.log"
				layout="${longdate}|${level}|${message} |${all-event-properties} ${exception:format=tostring}" />
		<target xsi:type="Console" name="logconsole"
				layout="${longdate}|${level}|${message} |${all-event-properties} ${exception:format=tostring}" />
	</targets>

	<!-- rules to map from logger name to target -->
	<rules>
		<logger name="*" minlevel="Trace" writeTo="logfile,logconsole" />
	</rules>
</nlog>

Simple program

var logger = LoggerFactory.Create(builder => builder.AddNLog()).CreateLogger<Program>();
logger.LogInformation("hello info!");
logger.LogTrace("hello trace!");
var web3 = new Web3("http://localhost:8545", logger);
var blocknumber = await web3.Eth.Blocks.GetBlockNumber.SendRequestAsync();
Console.ReadLine();

About

Logging trace requests example using nlog

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages