You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.7 KiB
50 lines
1.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using NLog;
|
|
using NLog.Common;
|
|
using NLog.Targets;
|
|
using NLog.Config;
|
|
|
|
namespace Helper
|
|
{
|
|
public static class NLogHelper
|
|
{
|
|
public static void LogConfig(ref NLog.Logger Logger)
|
|
{
|
|
var configuration = new NLog.Config.LoggingConfiguration();
|
|
//var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "logfile.txt" };
|
|
//var logconsole = new NLog.Targets.ConsoleTarget("logconsole");
|
|
var dbTarget = new DatabaseTarget();
|
|
|
|
dbTarget.ConnectionString = @"Server=SHU01\SHU00;Database=edoka_journale;User ID=sa;Password=*shu29";
|
|
|
|
dbTarget.CommandText =
|
|
@"INSERT INTO NLog ([Origin], [Message], [LogLevel],[UserID]) VALUES (@Origin,@Message,@LogLevel, @UserID);";
|
|
|
|
dbTarget.Parameters.Add(new DatabaseParameterInfo("@Origin", new NLog.Layouts.SimpleLayout("${callsite}")));
|
|
|
|
dbTarget.Parameters.Add(new DatabaseParameterInfo("@Message", new NLog.Layouts.SimpleLayout("${logger}")));
|
|
|
|
dbTarget.Parameters.Add(new DatabaseParameterInfo("@LogLevel", new NLog.Layouts.SimpleLayout("${level}")));
|
|
|
|
|
|
dbTarget.Parameters.Add(new DatabaseParameterInfo("@UserID", new NLog.Layouts.SimpleLayout("${message}")));
|
|
|
|
dbTarget.Parameters.Add(new DatabaseParameterInfo("@exception", new NLog.Layouts.SimpleLayout("${exception}")));
|
|
|
|
configuration.AddTarget("database", dbTarget);
|
|
|
|
|
|
}
|
|
|
|
public static string NameOf(this object o)
|
|
{
|
|
return o.GetType().Name;
|
|
}
|
|
|
|
}
|
|
}
|