How to configure NLog file-based logging in app.config file - ignite

Can we configure NLog file-based logging in app.config file ? Following link
https://apacheignite-net.readme.io/docs/logging has an programed way of doing it in c#, but no example of completely configuring it in app.config file!

There's a tab named "app.config" there in the docs section that shows the following example:
<igniteConfiguration>
<logger type="Apache.Ignite.NLog.IgniteNLogLogger, Apache.Ignite.NLog" />
</igniteConfiguration>

Related

Base Directory path of different environments in nlog

I have .net core web api project with Production,Stage and Development environments. i used {baseDir} in filename of nlog target but when i run project it store log file in bin\netcoreapp3.1\netcoreapp3.1 folder.
I have a folder Logs and i want to store logs in this folder.
same in all environments i want that.
Anyone know how to do that please help me !!
for more detail :
nlog.config
<variable name="DefaultLayout" value="${longdate} ${processid} ${uppercase:${level}} ${logger:shortName=true} ${environment-user} ${local-ip} ${message} "/>
<targets async="true">
<target xsi:type="File" name="file" layout="${DefaultLayout}" fileName="${baseDir}\log-${shortdate}.log" />
</targets>
Thank you !!
The {baseDir} is the directory from which the code is executing, so what you're getting is correct.
If you want to use the content root path of your ASP.NET Core app you need to use ${aspnet-appbasepath} - ref.
You can specify it as fileName="${aspnet-appbasepath}\Logs\log-${shortdate}.log".
From the docs:
Introduced with NLog.Web.AspNetCore v4.5.0 and NLog.Web v4.5.2
Make sure you're targeting the respective version, otherwise you wouldn't be able to use ${aspnet-appbasepath}

Change logging in the Mule

I have a Mule project that I want to run from AnypointStudio. It uses the default log4j2.xml, but I want to change that.
According to the documentation (http://www.mulesoft.org/documentation/display/current/Logging+in+Mule), it is posible to put another log4j2.xml file on the classpath, but that does not work.
In the "run configuration" of Anypoint I added a classpath. In that classpath folder I added another log4j2.xml file, but that is ignored by the Mule, although it sees another file in that folder.
How do I add an log4j2.xml file?
Put your log4j2.xml config in src/test/resources, that way it won't be packaged in the app but will be available in Studio, when you launch the app.

Reason for backtick in config file?

Microsoft's instructions on EF configuration files show this example.
<databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[Blogging.BlogContext, MyAssembly], [Blogging.Migrations.Configuration, MyAssembly]], EntityFramework" />
What is the meaning of the `2 in the config file?
The MigrateDatabaseToLatestVersion has two type params.
From msdn:
When we create an instance of this initializer we need to specify the
context type (BlogContext) and the migrations configuration
(Configuration) - the migrations configuration is the class that got
added to our Migrations folder when we enabled Migrations.
So, that's why there's the `2 in the configuration file.

NUnit not reading the configuration file

I have written a NUnit tests for a .NET application. When I run the NUnit, it does not read the connection string values from the configuration file. I tried many solutions with out success, like
Adding <assembly name>.dll.config file in the path where NUnit loads the DLL file.
Adding the configuration settings in NUnit.exe.config/NUnit.gui.config
I wasn't able to read the configuration setting even when run in VSNunit. Is there a solution?
I've assumed
Assembly being tested: SomeNameSpace.MyClassLib
NUnit assembly with unit tests: SomeNameSpace.MyClassLib.Test
Try this:
Make sure that you have also copied your app.config to your NUnit Test DLL class library (i.e. project SomeNameSpace.MyClassLib.Test) as well.
Build your NUnit Project (e.g. to SomeNameSpace.MyClassLib/bin/debug) and make sure that following are in the bin\debug (or release) directory
the assembly to be tested,
the NUnit test DLL and
the configuration (SomeNameSpace.MyClassLib.Test.config)
any other assemblies needed by your DLL file being tested.
Edit your NUnit Project in the XML view of the NUnit GUI Project editor (menu Project → Edit, or just edit it in Notepad), and make sure that the test assembly (MyClassLib.Test.dll) and the configuration file names are relative to your appbase
For example,
<NUnitProject>
<Settings activeconfig="Debug" processModel="Default"
domainUsage="Default"
appbase="C:\Temp\MyProject\MyClassLib.Test" />
<Config name="Debug" binpathtype="Auto"
configfile="bin\Debug\MyClassLib.Test.dll.config">
<assembly path="bin\Debug\MyClassLib.Test.dll" />
</Config>
<Config name="Release" binpathtype="Auto" />
</NUnitProject>
Add an app.config file to the test project and add your configurations in there.
You then have to tell NUnit what configuration to use as by default it will not pick up the app.config file.
More information on how to set this up with screenshot.
I was stuck on a similar issue for a while. We also need to look at how you are loading the assemblies, based on that the naming of configuration file changes (unless you are using an explicit configuration file from settings). As mentioned here:
http://www.nunit.org/index.php?p=configFiles&r=2.2.10
If a single assembly is being loaded, then the configuration file is given the name of the assembly file with the config extension. For example, the configuration file used to run nunit.tests.dll must be named nunit.tests.dll.config and located in the same directory as the DLL file.
If an NUnit project is being loaded, the configuration file uses the name of the project file with the extension changed to configuration. For example, the project AllTests.nunit would require a configuration file named AllTests.config, located in the same directory as AllTests.nunit. The same rule is followed when loading Visual Studio projects or solutions.

MSBuild or StyleCop task to verify key in App.config file?

In several projects’ App.config file, there is a line
<add key="url" value="http://www.example.com/"/>
Upon each build, I want to have a task to verify that the "url" key does not have the text "http://localhost". Is there a way to do this?
I'm assuming you have a team, and some of your team members inadvertently checkin those configs, changing that value to localhost.
If this is the case, why not have transform files for each environment, where your debug configuration can set the key to localhost, and your production/test/stage/qa/whatever configuration can set it to example.com or something else.
You might not have been aware that msbuild can transform your config files. Essentially you have your main config file, and then a config file containing just the things changed, for each environment. Upon doing a build, msbuild will modify the main one with whatever the changes are in the other "transform" files.
App.Config Transformation for projects which are not Web Projects in Visual Studio 2010?
Your transform file would look like:
<?xml version="1.0"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="url" value="http://www.example.com/" xdt:Locator="Match(key)" xdt:Transform="SetAttributes"/>
</appSettings>
</configuration>
The microsoft link is to http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx
They can easily be used on web.configs, as well as app.configs, with a little tweaking to your project file.
An alternative solution would be to integrate unit tests as part of your build, and have the test verify the key in your web.config.
Go to your builds:
Right click on your build and click on edit build definition:
Choose process:
Now we can set fail on build here: