Created
August 22, 2011 13:22
-
-
Save rstackhouse/1162357 to your computer and use it in GitHub Desktop.
Revisions
-
rstackhouse revised this gist
Aug 22, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -55,7 +55,7 @@ namespace ConsoleApplication1 config.LoggingRules.Add(dbRule); LogManager.Configuration = config; //doesn't work if moved after instatiation of config _logger = LogManager.GetCurrentClassLogger(); -
rstackhouse created this gist
Aug 22, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; using NLog; using NLog.Common; using NLog.Targets; using NLog.Config; namespace ConsoleApplication1 { class Program { private static Logger _logger; static void Main(string[] args) { //InternalLogger.LogToConsole = true; //InternalLogger.LogLevel = LogLevel.Trace; var config = new LoggingConfiguration(); var target = new FileTarget{ FileName=typeof(Program).FullName + ".log" }; config.AddTarget("logfile", target); var dbTarget = new DatabaseTarget(); dbTarget.ConnectionString = @"<server>;Initial Catalog=<database>;Persist Security Info=True;User ID=<user>;Password=<password>"; dbTarget.CommandText = @"INSERT INTO [Log] (Date, Thread, Level, Logger, Message, Exception) VALUES(GETDATE(), @thread, @level, @logger, @message, @exception)"; dbTarget.Parameters.Add(new DatabaseParameterInfo("@thread", new NLog.Layouts.SimpleLayout("${threadid}"))); dbTarget.Parameters.Add(new DatabaseParameterInfo("@level", new NLog.Layouts.SimpleLayout("${level}"))); dbTarget.Parameters.Add(new DatabaseParameterInfo("@logger", new NLog.Layouts.SimpleLayout("${logger}"))); dbTarget.Parameters.Add(new DatabaseParameterInfo("@message", new NLog.Layouts.SimpleLayout("${message}"))); dbTarget.Parameters.Add(new DatabaseParameterInfo("@exception", new NLog.Layouts.SimpleLayout("${exception}"))); config.AddTarget("database", dbTarget); var rule = new LoggingRule("*", LogLevel.Debug, target); config.LoggingRules.Add(rule); var dbRule = new LoggingRule("*", LogLevel.Debug, dbTarget); config.LoggingRules.Add(dbRule); LogManager.Configuration = config; _logger = LogManager.GetCurrentClassLogger(); _logger.Debug("Using programmatic config"); } } }