NLog: Unable to implement NLog when hosting medium trust level application on shared server

  • Bug : Server throws Security exception when medium level trust application is hosted. I am hosting my application in Shared Server. I have referred this issue and but couldn’t exactly get how to resolve this.

NLog version: 4.3.11

Platform: .Net 4.0

Current NLog config

<configSections>
       <section name="nlog" type="NLog.Config.ConfigSectionHandler,NLog"/>
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets>
      <target name="logfile" xsi:type="File" fileName="${basedir}APILog\${date:format=yyyy-MM-dd}-api.log"/>
    </targets>
    <rules>
      <logger name="*" minlevel="Trace" writeTo="logfile"/>
    </rules>
</nlog>

In case of a BUG:

  • What is the current result? - The above said exception
  • What is the expected result? - The application should log errors as this works in local system
  • Please post full exception details (message, stacktrace, inner exceptions)

“ExceptionMessage”: “Request for the permission of type ‘System.Configuration.ConfigurationPermission, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ failed.”, “ExceptionType”: “System.Security.SecurityException”, “StackTrace”: " at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)\r\n at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)\r\n at System.Security.CodeAccessPermission.Demand()\r\n at System.Configuration.BaseConfigurationRecord.CheckPermissionAllowed(String configKey, Boolean requirePermission, Boolean isTrustedWithoutAptca)" }

  • Are there any work arrounds? No. As of now I’ve commented the above configuration and it works fine.
  • Is there a version in which it did worked? N/A

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 25 (12 by maintainers)

Most upvoted comments

4.4.1 has been released!

Great! Will merge it for NLog 4.4.1. Also thanks to @snakefoot!

@kshkrao3 update! :

https://www.nuget.org/packages/NLog/4.4.1-dev-b4085

Install-Package NLog -Version 4.4.1-dev-b4085 -Pre

Here is the exception details if you want

It’s not the same as before I think, but we could fix it with that stacktrace

Should this NLog.Config file be presented in my application root folder.

That’s one of the options. See also https://github.com/NLog/NLog/wiki/Configuration-file#configuration-file-locations

Build is still building…

@304NotModified Could you please how can I do it with separate nlog.config fil

Put your config in nlog.config, https://github.com/NLog/NLog/wiki/Tutorial#configuration

Also I updated the library from NuGet but still am facing the SecurityException issue

Yes it’s not on nuget yet. Will release a private package in a few minutes