Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq2DB Nlog or logging

is there a way to log all linq2DB sql queries that are made to he database with NLog?

I cannot find any realistic example. There is something for miniprofiler, but this doesn't help me, because I have not experience with it.

pull request

example

example 2

like image 250
Franki1986 Avatar asked May 01 '17 15:05

Franki1986


1 Answers

Inside your Setup method you could turn on Trace and setup WriteTraceLine to Console.WriteLine

[SetUp]
public void Setup()
{
    LinqToDB.Data.DataConnection.TurnTraceSwitchOn();
    LinqToDB.Data.DataConnection.WriteTraceLine = (message, displayName) => { Console.WriteLine($"{message} {displayName}"); };
}

This will write all executed SQL Queries (together with params) to the Console

like image 183
croban Avatar answered Sep 24 '22 15:09

croban