Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to put NLog.config information inside of my app.config file?

Tags:

Is there a way to put NLog.config information inside of my app.config file? This way I can have one config file instead of two. It could look like this:

<?xml version="1.0" encoding="utf-8" ?> <configuration>   <configSections>     <section name="nlog" type="..." />   </configSections>   <nlog>     <targets>...</targets>     <rules>...</rules>   </nlog> </configuration> 

Please let me know if this is a duplicate.

like image 238
user2023861 Avatar asked Nov 05 '14 19:11

user2023861


People also ask

What can be configured with this NLog config file?

The following types can be configured: Targets - the destinations of a logevent, e.g. file, database, console. Layout - the layout e.g. json, csv, plain-text (default) Layout renderers - the template markers, e.g. ${message}, ${exception}, ${date}

How do I edit NLog config file?

You can find the NLog. config file in {Project Folder}\bin\Debug\net5. 0\ . You can open and edit it as you like with Notepad or Visual Studio.

How do I configure nlog in Visual Studio?

NLog configuration is formatted as XML and is either embedded in a Visual Studio project config file (app.config or web.config) or is a stand-alone XML file (Remember to configure File Properties: Copy If newer) To embed NLog config XML inside app.config / web.config file, add an nlog section element under configSections and add an nlog element.

What config files should I send to extend nlog?

See extending NLog . Missing or incorrect info? Feel free to edit the config and send a PR for the following config files: targets.json, layouts.json or layout-renderers.json

How do I configure nlog to swallow run-time exceptions?

NLog is designed to swallow run-time exceptions that may result from logging. The following settings can change this behavior and/or redirect these messages. <nlog throwExceptions="true" /> - adding the throwExceptions attribute in the config file causes NLog to stop masking exceptions and pass them to the calling application instead.

What is the use of nlog library?

NLog is a C# library used for logging. It is highly configurable, used by many projects. It supports by default various destinations for logs. I recommend using the NLog or Serilog. These two libraries are very similar and they have the most number of destinations already implemented.


1 Answers

Of course that you can put the configuration in your app.config file.

You just need to use the NLog.Config.ConfigSectionHandler so you need to write

<?xml version="1.0" encoding="utf-8" ?> <configuration>   <configSections>     <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>   </configSections>   <nlog>     <targets>...</targets>     <rules>...</rules>   </nlog> </configuration> 

as described in the NLog documentation in the Configuration file format section.

like image 95
nemesv Avatar answered Sep 22 '22 15:09

nemesv