Questions tagged [nlog]

NLog is a free logging platform for .NET

NLog is a logging platform for .NET with support for structured logging. NLog enables easy routing and filtering of output to various targets.

Resources

2784 questions
19
votes
2 answers

How to force nlog to throw an exception when the logging to database fails?

When I take down the database that backs nlog, nothing gets get logged and it seems NLog swallows the problem. Is there any way to configure it to raise and exception or at least to log in a text file that logging failed? Here is what my…
m0s
  • 4,250
  • 9
  • 41
  • 64
19
votes
1 answer

NLog and final rules

Very often I want to exclude logging from a specific chatty logger up to a certain level. Unfortunately, the first of the following rules is final for all levels of that logger, so that the second rule (which is simply my default rule) will not log…
John
  • 6,693
  • 3
  • 51
  • 90
18
votes
2 answers

Why would one use ELMAH if the application is using NLog

I have to write a centralized logging framework. Basic requirements are: Log exceptions as well as other details if needed to SQL Server DB. If DB is down i.e. a failover option is to log to a file and email I had done some reading around and…
gbs
  • 7,196
  • 5
  • 43
  • 69
17
votes
3 answers

Log current page url with NLog

I'm trying to log the current pages URL as part of our NLog layout. I've scoured the NLog layout variables and have come up with nothing. Does anyone know how to get the current page URL as a variable for the layout? Also is it possible just to…
Mike737
  • 836
  • 5
  • 16
17
votes
6 answers

Better TypeInitializationException (innerException is also null)

Intro When an user creates a mistake in the configuration of NLog (like invalid XML), We (NLog) throw a NLogConfigurationException. The exception contains the description what is wrong. But sometimes this NLogConfigurationException is "eaten" by a…
Julian
  • 33,915
  • 22
  • 119
  • 174
17
votes
3 answers

Create NLog file with current date and time without caching it, keeping the archive file name the same

I'm using NLog to do some logging and I've run into an issue with the archiving and filenames. I'm creating the logging configurations in code (I'm writing a wrapper to expose some specific functionality), and I've got the FileTarget object created…
Brandon
  • 4,491
  • 6
  • 38
  • 59
17
votes
3 answers

How do I use Microsoft Application Insights with NLog (Target cannot be found: 'ApplicationInsights')

I am using Microsoft Application Insights for my Web Application. I used the Application Insights TraceListener NuGet package for logging. That worked perfectly. Now I would like to switch to NLog. I added the…
17
votes
1 answer

Can I configure NLog to prune logs after they reach a certain limit?

Can NLog be configured to automatically prune/trim a log file after it reaches a certain file size?
Omar
  • 39,496
  • 45
  • 145
  • 213
16
votes
3 answers

Nlog Callsite is wrong when wrapper is used

I'm using NLog for logging, I use a wrapper to call log methods, my problem is: if I try to print information about the call site (${callsite}), it prints the wrapper method and not the original method that caused the logger to log. Is there any way…
Stacker
  • 8,157
  • 18
  • 73
  • 135
16
votes
3 answers

C# NLog; Cannot find NLog.xsd file

Just for the case that somebody produces one day the same error. In the starting section of the NLog.config file Visual Studio tells me (with a warning) that it cannot find the NLog.xsd File
Mong Zhu
  • 23,309
  • 10
  • 44
  • 76
16
votes
1 answer

Registering NLog ILogger with Simple Injector

Is there any way I can get the context so I can retrieve the loggerName and use LogManager.GetLogger(loggerName) instead of LogManager.GetCurrentClassLogger()? I noticed container.RegisterConditional() has access to the context. Also, I want to…
16
votes
5 answers

Nlog output characters if exception not null

Is there a way in Nlog to output certain character only if Exception is not null. For example my layout is: layout="${longdate}|${callsite:skipFrames=1}|${message}|${exception:format=tostring}" If I call NLog.Debug("Hello") the output will be:…
Bagzli
  • 6,254
  • 17
  • 80
  • 163
16
votes
2 answers

Is this the correct way to log to a specific target with NLog?

I'd like to log some special events into a different table that will contain more data then the general application log. If I add a second database target to the NLog.config how can I use it in my code? Would this be the right thing to do: NLog …
t3chb0t
  • 16,340
  • 13
  • 78
  • 118
16
votes
4 answers

Ninject logger using NLog

I've just started learning Ninject but have come across a problem with the logger. I've currently got a controller that has a service and logger injected into the constructor like so: public ToolsController(IToolsService toolsService, ILogger…
user1883004
  • 427
  • 2
  • 7
  • 17
15
votes
3 answers

decent log viewer that works with NLog

What would be a the best viewer that works well with NLog when I have the following requirements: I need to view logs offline (files) and online (live) for offline I need to be able to select and view multiple files that are then all displayed in…
bitbonk
  • 48,890
  • 37
  • 186
  • 278