If you want to enable logging for the Neo4j .Net driver, you can use the following additional configuration method: WithLogger
This should be considered after engaging with the support team and should not be the first element to bring to your support ticket.
See the example below for how to use it within your code, please note that the resulting LogFile.txt
produced in this example is located in bin/Debug/net6.0/
of the created .Net project folder.
using Neo4j.Driver;
using NLog; //Common logging framework in .net community.
//Wrap the chosen logging framework, in this case NLog, in a Neo4j logging interface.
class LogWrapper : Neo4j.Driver.ILogger
{
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
public LogWrapper()
{
//Setup chosen logger system, in this case NLog.
var config = new NLog.Config.LoggingConfiguration();
var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "LogFile.txt" };
config.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, logfile);
NLog.LogManager.Configuration = config;
}
public void Error(Exception cause, string message, params object[] args) => Logger.Error(cause, message, args);
public void Warn(Exception cause, string message, params object[] args) => Logger.Warn(cause, message, args);
public void Info(string message, params object[] args) => Logger.Info(message, args);
public void Debug(string message, params object[] args) => Logger.Debug(message, args);
public void Trace(string message, params object[] args) => Logger.Trace(message, args);
public bool IsTraceEnabled() { return true; }
public bool IsDebugEnabled() { return true; }
}
//When creating the driver object call ConfigBuilder.WithLogger passing in the concrete implementation of the Neo4j.ILogger interface.
using var driver = GraphDatabase.Driver(Uri, AuthTokens.Basic(User, Password), o => { o.WithLogger(new LogWrapper()); });
See logging levels for .Net
Comments
0 comments
Please sign in to leave a comment.