edosoft
edosoft

Reputation: 17271

Using LinqToSql with NLog

I'm writing an .NET 3.5 web application that is using LinqToSql for the basic database stuff. I'd like to use the nLog library for logging. This library can log to a database using good ol' fashioned stored procedures (not that there is anything wrong with that..) but I'd like to use the LingToSql DataContext to log to the database

Does anyone know how to do this? I am aware version 2.0 of nLog is coming, but it's not here yet...

-Edoode

Upvotes: 0

Views: 578

Answers (2)

Pablonete
Pablonete

Reputation: 1524

I think what @edosoft was looking for is something like this:

http://weblogs.asp.net/grantbarrington/archive/2010/02/08/sending-the-output-from-linq-to-sql-to-a-log-file.aspx

A simple TextWriter you can assign to DataContext.Log property instead of Console.Out to register LinqToSql logging using NLog.

Upvotes: 1

Spence
Spence

Reputation: 29342

Write your own target in NLog

If you wish to use LINQ to do it, then create your own target to write to. I don't see why if you have SProcs though, the fastest possible way to write messages using C# to a database (bar a bulk load) is via the native SQL api and calling a stored proc. Plus if someone has already written a DB target for you...

Upvotes: 2

Related Questions