Code Coverage by Clover.NET

Open file log

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

Open file log

by jvela :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello, first of all Nlog is GREAT!!.

I create my own log target and it work ok. I've got two targets, one of them writes a trace into a file, and my log target send a mail when an exception is lanched and I want sent the trace file or a part of it. Is it possible?


Thanks and regards

Re: Open file log

by Jaroslaw_Kowalski :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This is not directly possible with NLog but there are at least two methods you can use:

1. Create a new layout renderer which reads from a file. Something like:

${filecontents:filename=file.txt}

and use this to read the contents of the trace file.

2. I'm not sure, but it looks like the new PostFilteringWrapper available in the latest snapshots may be what you want:

http://www.nabble.com/New-NLog-features-t449777c6167.html

You can basically buffer all your messages in memory and send them down to the specified target as soon as any condition is met. For example you can:

a) buffer the entire ASP.NET request in memory
b) as soon as the request finishes, check the buffer contents:
   i) if it contains any >= Warn message - dump the buffer contents including any messages at the Debug level and above
   ii) if it contains any >= Error message - dump the buffer contents including any messages at the Trace level and above
   iii) otherwise just output the Info level and above messages

Hope it helps,

Jarek

Re: Open file log

by jvela :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I found another method i put in my target a variable with a layout to get the name file and then read from the file (more easy).

regards

Re: Open file log

by John H. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
could you please describe your method of doing this?

Thanks, John.