nlog.config

210 views
Skip to first unread message

alessandro bonvicini

unread,
Oct 21, 2020, 6:44:52 AM10/21/20
to CS-Script
Hi all,
I using cscs 3.30.03.
I voul like to include in my script the NLog.config (xml) to start logging.
But this does not happen. Seems that cscs ignore the Nlog.config file....
Please may you help me to understand whats happen?
Thank you very much in advance
Alessandro


*********
the config file


<nlog>

    <targets>
        <target name="logfile"  xsi:type="File" fileName="P:\\Sync\\sandro\\lavoro\\c#\\vari_test\\loggo.txt" />
       
    </targets>

    <rules>
          <logger name="ciccio" minlevel="Trace" maxlevel="Error" final="true" writeTo="logfile" />
    </rules>
</nlog>

***************
the script file


//css_nuget NLog;

using NLog;
using NLog.Common;

using NLog.Targets;
using NLog.Targets.Wrappers;

using System;
using System.Diagnostics;



class Program
{
    // Make sure to comment out static Logger-objects, or else InternalLogger will not work
    // readonly static Logger = LogManager.GetCurrentClassLogger();

    static void Main()
    {   NLog.LogManager.ThrowExceptions = true;
        NLog.Common.InternalLogger.LogLevel = LogLevel.Debug;
        NLog.Common.InternalLogger.LogToConsole = true;
        NLog.Common.InternalLogger.LogFile = "P:\\Sync\\sandro\\lavoro\\c#\\vari_test\\NLog.Internal.txt";
        Logger logger = NLog.LogManager.GetLogger("ciccio");
        logger.Info("Program started");
        LogManager.Shutdown();  // Remember to flush
    }
}
*****
the output
2020-10-21 12:32:19.2560 Debug Found assembly location directory: 'C:\ProgramData\chocolatey\lib\cs-script\tools\cs-script' (cscs, Version=3.30.3.0, Culture=neutral, PublicKeyToken=null)
2020-10-21 12:32:19.2610 Debug Targets not configured for logger: ciccio
2020-10-21 12:32:19.2767 Info Shutdown() called. Logger closing...
2020-10-21 12:32:19.2767 Info Logger has been closed down.
2020-10-21 12:32:19.3001 Info AppDomain Shutting down. Logger closing...
2020-10-21 12:32:19.3001 Info Logger has been shut down.

Oleg Shilo

unread,
Oct 22, 2020, 6:49:04 AM10/22/20
to CS-Script
> Seems that cscs ignore the Nlog.config file....

Actually it is vise versa.
NLog runtime loads NLog.config file at startup. It looks for this file in the folder where the entry assembly is. And it is an NLog design limitation as in case of the script execution  your entry assembly is the script engine.

Thus to fix this problem you will need to find a way to explicitly initialize NLog with a custom config file at start up.
There will be something in NLog documentation. I don't know the answer. But may be NLog users do.

BTW you are better off to use GitHub for getting any CS-Script discussion: https://github.com/oleg-shilo/cs-script

Oleg Shilo

unread,
Oct 22, 2020, 6:53:04 AM10/22/20
to CS-Script
Here we go. Apparently NLog allows custom config files an easy way. So they have already solved this problem:

```
NLog.Config.XmlLoggingConfiguration("location of your NLog.config file", true);
```

alessandro bonvicini

unread,
Oct 22, 2020, 7:58:13 AM10/22/20
to cs-s...@googlegroups.com
Hi Oleg,
thank you very much for your support and for your work.
After many trials , i discovered that the problem was
this directive
//css_nuget NLog;

using NLog;
using NLog.Common;
using System.Xml;
using NLog.Targets;
using NLog.Targets.Wrappers;
---------->>>>>>>>using NLog.Config;

using System;
using System.Diagnostics;

and the name of the NLOG config file  NLog.conf
I changed the name to My.nlog  and voilà it works!

Something with name clash ?
 I do not kno w but an error message of the scripting engine when cscs starts was
"nlog.conf is damaged".... So i though that the loader load the nlog.conf xml instead of nlog.config assembly.....

Any way i have another problem now. ..tried the extension in  visual studio  2015 2017 and 2019
and everytime the message is
immagine.png

The version i use is that of chocolate 3.30.3.0 ...I do not found any other version....what is the problem here?
thank you very much
Alessandro


--
You received this message because you are subscribed to a topic in the Google Groups "CS-Script" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cs-script/ZuKwBI5TGKU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cs-script+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cs-script/1a476275-5a17-465d-b293-b18f14667228n%40googlegroups.com.


--

Alessandro Bonvicini
alle...@gmail.com

3311252848

alessandro bonvicini

unread,
Oct 22, 2020, 10:05:23 AM10/22/20
to cs-s...@googlegroups.com
Trying to use the extension for visual studio  2019 i  got the following
immagine.png
Cs-script extension is disabled , no compatible cs-script version found min3.4.2

But i have installed the 3.30.3.0
The same in vs studio 2015 and 2017  and for project based on framework .net 3.0 and 3.5
Please help , what can i do?
Thank a lot in advance



Il giorno gio 22 ott 2020 alle ore 12:49 Oleg Shilo <oleg....@gmail.com> ha scritto:
--
You received this message because you are subscribed to a topic in the Google Groups "CS-Script" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cs-script/ZuKwBI5TGKU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cs-script+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cs-script/1a476275-5a17-465d-b293-b18f14667228n%40googlegroups.com.

Oleg Shilo

unread,
Oct 23, 2020, 10:06:37 PM10/23/20
to CS-Script
I moved this discussion on GitHub as Google-groups does not make it easy.
https://github.com/oleg-shilo/CS-Script.VSIX/issues/4

I posted the answer there
Reply all
Reply to author
Forward
0 new messages