Code Coverage by Clover.NET

How do display NLog output file (programmatically)?

View: New views
4 Messages — Rating Filter:   Alert me  

How do display NLog output file (programmatically)?

by amores perros :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In my previous solution, after certain crashes, I put up a message box
offering to display the log.

I'm having trouble figuring out how to do that with NLog.

I got this far:

                NLog.Config.LoggingConfiguration cfg = new
NLog.Config.LoggingConfiguration();
                foreach (NLog.Target targ in cfg.GetConfiguredNamedTargets())
                {
                        if (targ. // How do I figure out if it is a file target?
// How do I get its fully qualified path, so I can display it?
                }


Is this doable?
If so, how?
If not, do you have any suggestions for me?


Thanks for any ideas.




-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Nlog-list mailing list
Nlog-list@...
https://lists.sourceforge.net/lists/listinfo/nlog-list

Re: How do display NLog output file (programmatically)?

by Jaroslaw_Kowalski :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

amores perros wrote:

> In my previous solution, after certain crashes, I put up a message box
> offering to display the log.
>
> I'm having trouble figuring out how to do that with NLog.
>
> I got this far:
>
> NLog.Config.LoggingConfiguration cfg = new
> NLog.Config.LoggingConfiguration();
> foreach (NLog.Target targ in cfg.GetConfiguredNamedTargets())
> {
> if (targ. // How do I figure out if it is a file target?
> // How do I get its fully qualified path, so I can display it?
> }
>
>  
The simplest way is to do:

FileTarget ft = (FileTarget)NLog.Configuration.FindTargetByName("f")

where "f" is the name of the target you want.

Alternatively you can do it like this:

foreach (Target t in NLog.Configuration.GetConfiguredNamedTargets())
{
    if (t is FileTarget)
    {
         FileTarget ft = t as FileTarget;
         //
    }
}

Jarek


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Nlog-list mailing list
Nlog-list@...
https://lists.sourceforge.net/lists/listinfo/nlog-list

Re: How do display NLog output file (programmatically)?

by amores perros :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message




>From: Jaroslaw Kowalski
>Subject: Re: [Nlog-list] How do display NLog output file
>(programmatically)?
>Date: Mon, 17 Jul 2006 06:51:55 +0200
>
...

>
>FileTarget ft = (FileTarget)NLog.Configuration.FindTargetByName("f")
>
>where "f" is the name of the target you want.
>
>Alternatively you can do it like this:
>
>foreach (Target t in NLog.Configuration.GetConfiguredNamedTargets())
>{
>    if (t is FileTarget)
>    {
>         FileTarget ft = t as FileTarget;
>         //
...

Doh! Thank you very much.




-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Nlog-list mailing list
Nlog-list@...
https://lists.sourceforge.net/lists/listinfo/nlog-list

Re: How do display NLog output file (programmatically)?

by SN :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes I managed this, but when I then try to access til target.Filename property i get:

"${basedir}/MyApp.log"

ie. the config file variable is not resolved.

How can I programmatically read the FILE CONTENTS OF THE LOG FILE written by a file target ?


Jaroslaw_Kowalski wrote:
amores perros wrote:
> In my previous solution, after certain crashes, I put up a message box
> offering to display the log.
>
> I'm having trouble figuring out how to do that with NLog.
>
> I got this far:
>
> NLog.Config.LoggingConfiguration cfg = new
> NLog.Config.LoggingConfiguration();
> foreach (NLog.Target targ in cfg.GetConfiguredNamedTargets())
> {
> if (targ. // How do I figure out if it is a file target?
> // How do I get its fully qualified path, so I can display it?
> }
>
>  
The simplest way is to do:

FileTarget ft = (FileTarget)NLog.Configuration.FindTargetByName("f")

where "f" is the name of the target you want.

Alternatively you can do it like this:

foreach (Target t in NLog.Configuration.GetConfiguredNamedTargets())
{
    if (t is FileTarget)
    {
         FileTarget ft = t as FileTarget;
         //
    }
}

Jarek


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Nlog-list mailing list
Nlog-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nlog-list
LightInTheBox - Buy quality products at wholesale price