Problem with NLOG and ASP.NET

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Problem with NLOG and ASP.NET

calamidad
Hello,
I´m trying to use NLOG with ASP.NET variables. First i try to get some logs with the default configuration and it goes correctly. But when I tried to introduce any new parameter I got this exception:

"Exception occurred when loading configuration from C:\...\NLog.config"

My NLOG.config is this:

<?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"
      throwExceptions="true"
      autoReload="true">
 
    <targets>
        <target name="logfile" xsi:type="File" fileName="${basedir}/logs/${date:format=yyyy-MM-dd}_log.txt" />
        <target name="logfile2" xsi:type="File" fileName="${basedir}/logs/${date:format=yyyy-MM-dd}_trace.txt"
                layout="${longdate} ${newline}${level} | ${message})" />
        <target name="db" xsi:type="Database" keepConnection="true" useTransactions="false"  dbProvider="MySql.Data.MySqlClient"
              connectionString="Data Source=ServerNAME;userid=user;password=secret;database=my_db;"
              commandText="INSERT INTO logtable (timestamp, message, level, logger) VALUES(now(), @msg, @level, @logger)">
           
            <parameter name="@msg" layout="${message}" />
            <parameter name="@level" layout="${level}" />
            <parameter name="@logger" layout="${logger}" />

        </target>
    </targets>

    <rules>
        <logger name="*" minlevel="Debug" writeTo="logfile" />
      <logger name="*" maxlevel="Trace" writeTo="logfile2" />
      <logger name="*" level="Info" writeTo="db" />
    </rules>
</nlog>

I want to get the IP adress of the client and some aplication and session variables like these:

<target name="logfile2" xsi:type="File" fileName="${basedir}/logs/${date:format=yyyy-MM-dd}_trace.txt"
  layout="${longdate} ${newline}${level} | ${message} ${aspnet-request:serverVariable=REMOTE_ADDR} $(aspnet-session:idUser:string)})"

Some one could tell me how to resolve this problem?

Thank you very much in advance.

Regards,
Cala!

PS: I've searched hard in the forum, but I didnt find a solution yet. :(
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with NLOG and ASP.NET

calamidad
Hello,
I´m would like to use the Asp-session layout renderer. At the moment i´m testing with this example:
${aspnet-session:variable=user}

Previously i have set value of the ASP.NET Session variable "user" by using the following code:
HttpContext.Current.Session["user"] = "user1";

But it doesn´t work. I get this exception:
Exception occurred when loading configuration from C:\...\NLog.config

 I think I need to write something in my Nlog.config, but i don´t have any idea of what should I do.

Could someone help me?

Thx you in advance!

Regards!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with NLOG and ASP.NET

calamidad
In reply to this post by calamidad
Maybe i need to add another reference to my project in Visual Studio. I have added only NLog.dll ...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with NLOG and ASP.NET

Perry
In reply to this post by calamidad
As I just noted on some other thread, I noticed today that some of the aspnet renderers are in a section of the source code under a directory named NLog.Extended, which suggests that they may be implemented in the NLog.Extended.dll, so maybe you should double-check that you have that one available.

For your first example, the first thing I would do is start over with a really simple file target, and then if that works, you could start tweaking the simple file target toward the original complicated example, and also tweaking the complicated example toward the simple file target, to see where things go wrong.   (And I apologize if I'm pointing out the obvious - just trying to help.)

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with NLOG and ASP.NET

calamidad
Thak you very much Perry for your answer. I´m still trying with a very simple example, but I can´t get any log with any session aspnet varibles. I´ve already added the reference to the NLog.Extended Library, but I didn´t got nothing new.

I think I´ll look for another solution to my problem.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with NLOG and ASP.NET

Jarek Kowalski
Administrator


Please add this to your NLog.config:

<nlog>

<extensions>

<add asembly="NLog.Extended" />

</extensions>

...

</nlog>


+ make sure NLog.Extended.dll is in the same directory as NLog.dll

That should fix it.

 

Jarek

NLog Blog
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with NLOG and ASP.NET

calamidad
Thank you very much! It´s fixed. Now, it runs perfectly.

Regards!
Loading...