Author Topic: How to use NLog  (Read 2592 times)

0 Members and 1 Guest are viewing this topic.

bargool

  • Guest
How to use NLog
« on: January 10, 2012, 02:16:48 PM »
I'm trying to log my application with NLog, but the code
Code: [Select]
using System;
using System.Collections.Generic;
using acad = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using NLog;

[assembly:CommandClass(typeof(TestNLogAcad.MyClass))]
namespace TestNLogAcad
{
public class MyClass
{
private static Logger log = LogManager.GetCurrentClassLogger();

[CommandMethodAttribute("nlog")]
public void test()
{
log.Info("Hello NLog!");
acad.DocumentManager
.MdiActiveDocument.Editor
.WriteMessage("\nHello NLog!");
}
}
}
only writes message to command line. And there is no log file.
NLog.config:
Code: [Select]
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <!--
  See http://nlog-project.org/wiki/Configuration_file
  for information on customizing logging rules and outputs.
   -->
  <targets>
    <target name="file"  xsi:type="File" fileName="${basedir}/nlog.txt" layout="${date}|${level}|${message}" />
  </targets>
  <rules>
    <logger name="*" minlevel="Trace" writeTo="file" />
  </rules>
</nlog>
What is wrong in my solution?

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How to use NLog
« Reply #1 on: January 10, 2012, 02:25:54 PM »
Does LOGFILEON command not work for your situation?

bargool

  • Guest
Re: How to use NLog
« Reply #2 on: January 10, 2012, 02:41:21 PM »
Does LOGFILEON command not work for your situation?
Thank you, LOGFILEON works, but I want more  :ugly:
Well, I started new thread to understand this in general.
« Last Edit: January 10, 2012, 02:47:14 PM by bargool »

bargool

  • Guest
Re: How to use NLog
« Reply #3 on: February 13, 2013, 06:35:59 AM »
Hah! I was looser!
This was because NLog looked for configuration file in application directory.
Just need to load configuration from configfile:
Code - C#: [Select]
  1. XmlLoggingConfiguration config = new XmlLoggingConfiguration(LogSettingsFilePath);
  2. LogManager.Configuration = config;
I just remebered about this thread  :-)