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
362
votes
10 answers

Most useful NLog configurations

What are the best or most useful configurations for logging with NLog? (These can be simple or complex, as long as they're useful.) I'm thinking of examples like automatically rolling over log files at a certain size, changing the layout (log…
Pat
  • 16,515
  • 15
  • 95
  • 114
355
votes
15 answers

log4net vs. Nlog

Anyone have experience for both? How do they stack up against each other? We are planning on using one of them for logging in an enterprise application. References: log4net nlog EDIT: We have no existing dependencies to either nlog or log4net.
Greg Dean
  • 29,221
  • 14
  • 67
  • 78
94
votes
7 answers

Logger wrapper best practice

I want to use a nlogger in my application, maybe in the future I will need to change the logging system. So I want to use a logging facade. Do you know any recommendations for existing examples how to write those ones ? Or just give me link to some…
Night Walker
  • 20,638
  • 52
  • 151
  • 228
91
votes
10 answers

Why do loggers recommend using a logger per class?

As per NLog's documentation: Most applications will use one logger per class, where the name of the logger is the same as the name of the class. This is the same way that log4net operates. Why is this a good practice?
Daniel T.
  • 37,212
  • 36
  • 139
  • 206
79
votes
5 answers

Dependency injection and named loggers

I am interested in learning more about how people inject logging with dependency injection platforms. Although the links below and my examples refer to log4net and Unity, I am not necessarily going to use either of those. For dependency…
wageoghe
  • 27,390
  • 13
  • 88
  • 116
69
votes
2 answers

How can I output NLog messages to Visual Studio's Output Window?

I'm trying to send the output to the console (or colouredconsole) ... which I'm hoping would (also?) go to the Visual Studio's Output window for any ASP.NET web site/app/mvc app. It doesn't by default, but if I change the target to 'file' then it…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
68
votes
4 answers

How to get the Stack trace when logging exceptions with NLog?

When I use the default layout with NLog it only prints the name of the exception. I've been told that the log4jxmlevent layout doesn't prints nothing about the exception. What layout will help me? Example code: try { throw new…
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
66
votes
6 answers

How to get path of current target file using NLog in runtime?

I use NLog with next configuration:
Win4ster
  • 896
  • 1
  • 8
  • 15
58
votes
2 answers

NLog performance

What should the expected overhead be for logging? I have tried this example private class Person { private static Logger logger = LogManager.GetCurrentClassLogger(); public string Name { get; private set; } public Person(string name) …
Eric
  • 3,027
  • 6
  • 29
  • 34
57
votes
5 answers

How do I log a custom field in NLog to database?

I currently use NLog on a lot of projects. On some, I log to a database. Here is what I would like to do: CREATE TABLE [dbo].[NLogEntries]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [Origin] [nvarchar](100) NOT NULL, [LogLevel] [nvarchar](20) NOT…
Kjensen
  • 12,447
  • 36
  • 109
  • 171
54
votes
5 answers

using AppData location in NLog

My NLog targets is like this:
Malfist
  • 31,179
  • 61
  • 182
  • 269
52
votes
14 answers

NLog does not create a log file

I am trying to add logging to an application running on mobile device with Windows Mobile 6.1. � .NET Compact framework 3.5. using NLog. I have the appropriate version of the NLog distribution installed. However no log files are being created. Here…
Srv19
  • 3,458
  • 6
  • 44
  • 75
48
votes
3 answers

NLog time formatting

How do I write a layout for NLog that outputs time with milliseconds like this 11:32:08:123? I use ${date:format=yyyy-MM-dd HH\:mm\:ss} but I need more time precision in my logs.
levanovd
  • 4,095
  • 6
  • 37
  • 56
44
votes
7 answers

Reconfigure NLog LoggingConfiguration filters programmatically

This is my first time using the NLog package for logging but so far its been great to work with. In my scenario I need to initialize my NLog LoggingConfiguration settings programmatically rather than thru the more typical config file scenario. I've…
snappymcsnap
  • 2,050
  • 2
  • 29
  • 53
43
votes
1 answer

NLog: How to exclude specific loggers from a specific rule?

In my NLog configuration, I have a catch-all logger but a specific logger I have created is very spammy and I want its output to go to its own file. That part is easy, but the catch-all logger receives the spammy log messages as well. How do I tell…
Nathan Ridley
  • 33,766
  • 35
  • 123
  • 197
1
2 3
99 100