Why is EnvironmentPermission required?

3 messages Options
Embed this post
Permalink
xr280xr

Why is EnvironmentPermission required?

Reply Threaded More More options
Print post
Permalink
Hi,
All of the sudden I'm getting an exception that the EnvironmentPermission is required (but it is not granted) for nlog:


[SecurityException: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessPermission.Demand() +58
   System.Environment.GetEnvironmentVariable(String variable) +66
   NLog.LogFactory.get_Configuration() +608
   NLog.LogFactory.GetLogger(LoggerCacheKey cacheKey) +223
   NLog.LogFactory.GetLogger(String name) +57
   NLog.LogManager.GetLogger(String name) +15

 
I'm curious why I have been using nlog just fine but now it needs that permission. It's possible someone has changed something in the config file that I'm not aware of. Does anyone know why this permission is needed and what I need to grant to let it work? I don't really want to just give it Unrestricted access if I don't need to. Thanks.
xr280xr

Re: Why is EnvironmentPermission required?

Reply Threaded More More options
Print post
Permalink
Ok, so I downloaded the source code (though I couldn't get it using TortiseSVN like the site suggested because it was wanting a password) and after a quick look, I can see that when it's trying to get the logging configuration it tries a few locations and at one point resorts to checking for a global config file using the environment variable NLOG_GLOBAL_CONFIG_FILE. So apparently on my other machine where nlog has been working, it's been finding the config file before getting to this point, but on this machine it's not. It's also not currently logging on this machine making me think it might not be finding a config file at all. I have nlog in the GAC right now but not really sure where to put the config file I guess.

To answer part of my original question, I've configured the following permissions. I added all of the environment variables I could find in the Nlog solution.

<IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                    All="NLOG_GLOBAL_CONFIG_FILE;
                          NLOG_INTERNAL_LOG_FILE;
                          NLOG_INTERNAL_LOG_LEVEL;
                          NLOG_INTERNAL_LOG_TO_CONSOLE;
                          NLOG_INTERNAL_LOG_TO_CONSOLE_ERROR" />

Read access to NLOG_GLOBAL_CONFIG_FILE fixed the original error.
xr280xr

Re: Why is EnvironmentPermission required?

Reply Threaded More More options
Print post
Permalink
(This post was updated on )
After some more digging, and I apologize for the misinformation but I'm not the only one setting this stuff up, I've found that nlog is not in the gac on the machine I'm setting up. Which makes sense because it would have full trust if it were. It is in the bin of my Sharepoint site's directory. I also had to tweak my above permission because Sharepoint didn't like the All property.

<IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                    Read="NLOG_GLOBAL_CONFIG_FILE;                  
                             NLOG_INTERNAL_LOG_FILE;
                             NLOG_INTERNAL_LOG_LEVEL;
                             NLOG_INTERNAL_LOG_TO_CONSOLE;
                             NLOG_INTERNAL_LOG_TO_CONSOLE_ERROR"
                    Write="NLOG_GLOBAL_CONFIG_FILE;                  
                              NLOG_INTERNAL_LOG_FILE;
                              NLOG_INTERNAL_LOG_LEVEL;
                              NLOG_INTERNAL_LOG_TO_CONSOLE;
                              NLOG_INTERNAL_LOG_TO_CONSOLE_ERROR"/>

So does anyone know what it means if it gets to the point of looking at NLOG_GLOBAL_CONFIG_FILE when loading the configuration?