Share via


Nlog configuration file not getting loaded

Question

Wednesday, April 3, 2019 10:56 AM

Below stmt NLog.LogManager.Configuration = new XmlLoggingConfiguration("assets//NLog.config",true); gives me following error: The name 'new XmlLoggingConfiguration("assets\NLog.config")' does not exist in the current context. which in turn throws exception System.NullReferenceException: Object reference not set to an instance of an object.

I tried passing file name in all ways i could think of.

Also can anyone explain me does the above statement is used to log error in that file or that its just rules that are to be followed in the file? Do i have to create a new file where everything gets logged in?

Thanks,

All replies (8)

Tuesday, April 9, 2019 7:36 AM ✅Answered

Have a look at https://github.com/NLog/NLog/wiki/Logging-troubleshooting


Wednesday, April 3, 2019 12:14 PM

I don't use XmlLoggingConfiguration… I think NLogManager get NLog.config by default if you have set as AndroidAssets


Friday, April 5, 2019 9:20 AM

Yes its set to Android asset still its not working.


Friday, April 5, 2019 9:21 AM

what is "it's not working"?


Friday, April 5, 2019 9:23 AM

var config = new XmlLoggingConfiguration("assets/NLog.config"); NLog.LogManager.Configuration = config; The values of alltargets count and rules in the config object is 0. I'm not getting where i'm going wrong So basically it cannot read the config file mentione din asset folder


Friday, April 5, 2019 10:35 AM

For Xamarin Android, the assets folder is supported. "NLog.config" in the assets folder will be loaded automatically. If the file name is different, then use: LogManager.Configuration = new XmlLoggingConfiguration("assets/someothername.config");


Friday, April 5, 2019 12:03 PM

My existing project is portable code. I have installed nlog package in the android part of the project. have set the nlog config build action as android asset. and i also tried what you suggested above but its still not working. can you tell me if i should add something here or is it cuz of something else? and in the config file only targets and rules are specified


Monday, April 15, 2019 7:02 AM

hey guys thanks, but it got resolved on its own sorry to take up ur time