NLog: Problem using NLog.Config with Xamarin
I am trying to use the NLog.Config with Xamarin.iOS and Xamarin.Android Projects. I downloaded the NLog.Config package from nuget and I added inside the NLog.Config file:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="console" xsi:type="Console" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="console" />
</rules>
</nlog>
and inside the Main
static void Main (string[] args)
{
Logger logger = LogManager.GetCurrentClassLogger ();
logger.Trace("Sample trace message");
logger.Debug("Sample debug message");
logger.Info("Sample informational message");
logger.Warn("Sample warning message");
logger.Error("Sample error message");
logger.Fatal("Sample fatal error message");
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main (args, null, "AppDelegate");
}
But it does not work. It seems that the logger doesn’t load the configuration file. If I set the LoggingConfiguration inside the Main, it works prefectly. What I am missing?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 23 (14 by maintainers)
@Shiva799 Better to start new issue than to wake up sleeping giants. You have already received many answers here:
https://stackoverflow.com/questions/55488453/cannot-load-nlog-config-in-xamarin/55503067
And the NLog wiki also shows how to load NLog.config from project-resources:
https://github.com/NLog/NLog/wiki/Explicit-NLog-configuration-loading#loading-nlog-configuration-from-xamarin-resource