DataContext.Log Property

Definition

Gets or sets the destination to write the SQL query or command.

C#
public System.IO.TextWriter Log { get; set; }

Property Value

The writer to use for writing the command.

Examples

The following example displays generated SQL in the console window before it displays the results of the query.

C#
db.Log = Console.Out;
var custQuery =
    from cust in db.Customers
    where cust.City == "London"
    select cust;

foreach (var custObj in custQuery)
{
    Console.WriteLine(custObj.ContactName);
}

Remarks

Set this property to null to disable command logging.

Applies to

Product Versions
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1