Last updated: 2006-09-18
This website is based on NLog v20060918.
Click here to view the documentation
for other versions.
| Frequently Asked QuestionsHow do I properly log exceptions? Exceptions require special treatment in NLog. You need to call a Logger method which takes Exception as its second argument. The method names match available log levels:
Typically you call one of these methods in the
To write the details of the exception, use the How do I configure logging for a component? If you can configure logging on the client-side (by providing the appropriate configuration file in application's directory), you can follow the tutorial. However, if you do not control the clients, or they are not all local, or you wish a solution encapsulated to your component or assembly, you may wish to configure logging locally in your component assembly. The solution is to create a log manager just for your component that will manage its own loggers. You need to load the configuration file by hand and/or configure logging programmatically but your configuration will be independent from application's config. The following solution is usable for components not in the GAC. (Components in the GAC need to implement below method GetNLogConfigFilepath in some application-dependent fashion.)
Then create loggers with:
or
The loggers are independent from the ones created with NLog LogManager, and thus you can have safe private logging. That is, this will not interfere with other assemblies or the application exe itself using NLog. If you want multiple assemblies to share this MyLogManager - just make it a public class and get others to use it.
You need to make sure that the configuration is properly
closed when the process terminates (set
MyLogManager.Instance.Configuration to null) or you may
lose some log output.
You may want to hook AppDomain.ProcessExit and
AppDomain.DomainUnload events to turn off logging automatically.
See the code of LogManager.cs Last updated: 2006-07-18 19:44:49 | |||||||
| Copyright © 2004-2006 by Jarosław Kowalski. |