Nlog configuration file not getting loaded

Shiva799Shiva799 Member ✭✭

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,

Best Answer

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

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

  • Shiva799Shiva799 Member ✭✭

    Yes its set to Android asset still its not working.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    what is "it's not working"?

  • Shiva799Shiva799 Member ✭✭
    edited April 5

    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

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    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");

  • Shiva799Shiva799 Member ✭✭
    edited April 5

    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

  • Shiva799Shiva799 Member ✭✭

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

Sign In or Register to comment.