How to find the Config File location via ConfigurationManager?
I have the ConfigurationManager class in code and I'm debugging it. I'd like to know to which config file it's pointing to (web.config or app.config, etc).
Is there any property or method on the ConfigurationManager that can help with this?
The configuration file itself is represented by Configuration object. To get this object, run this:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
Then you can view the file path via config.FilePath.
Update. As pointed out by Schadensbegrenzer for web application you will need another code to load the config file:
Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
Related
This may be an easy question, but I am not sure if my mobile-config.js file is being loaded.
I am getting this error in the simulator:
ERROR whitelist rejection
And I read somewhere that I need to put:
App.accessRule('*');
in my mobile-config.js file.
But it doesn't seem to be working. Where should I put my mobile-config.js file?
Create a mobile-config.js file in your project root folder and add access rules as needed:
App.accessRule('https://*.mycdn.com/*');
App.accessRule('http://pbs.twimg.com/*');
After building your app you can check rules were applied in .meteor/local/cordova-build/config.hml where they should be listed as acess tags with origin attribute:
<access origin="https://*.mycdn.com/*"/>
<access origin="http://pbs.twimg.com/*"/>
I'm config a nginx, and debugging the config file,
How to show something from the config file directly to log file?
for example:
location ..... {
to_log "some string";
}
There is no direct way (on the todo list of the echo nginx module), but this solution seems fine https://serverfault.com/questions/404626/how-to-output-variable-in-nginx-log-for-debugging
has anyone tried to use a log4j.xml reference within a WinRun4j service configuration. here is a copy of my service.ini file. I have tried many configuration combinations. this is just my latest attempt
service.class=org.boris.winrun4j.MainService
service.id=SimpleBacnetIpDataTransfer
service.name=Simple Backnet IP DataTransfer Service
service.description=This is the service for the Simple Backnet IP DataTransfer.
service.startup=auto
classpath.1=C:\Inbox\DataTransferClient-1.0-SNAPSHOT-jar-with-dependencies.jar
classpath.2=WinRun4J.jar
classpath.3=C:\Inbox\log4j-1.2.16.jar
arg.1=C:\Inbox\DataTransferClient.xml
log=C:\WinRun4J-Service\SimpleBacnetIpDataTransfer\NBP-DT-service.log
log.overwrite=true
log.roll.size=10MB
[MainService]
class=com.shiftenergy.ws.App
vmarg.1=-Xdebug
vmarg.2=-Xnoagent
vmarg.3=-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
vmarg.4=-Dlog4j.configuration=file:C:\Inbox\log4j.xml
within the log4j.xml file, there is reference to a log file for when the application runs. if I run the java -jar -Dlog4j.configuration=file:C:\Inbox\log4j.xml ...., the log file is created accordingly. if I register my service and start the service, the log file does not get created.
has anyone had success using the -D log4j configuration, using winrun4j?
thanks
I think that you provided the vmarg.4 parameter incorrectly. In your case it has to be like:
vmarg.4=-Dlog4j.configurationFile=[Path for log4j.xml]
I am also using the same and in my case, it is working perfectly fine. Please see below example:
vmarg.1=-Dlog4j.configurationFile=.\log4j2.xml
Have you tried setting the path in your code instead:
System.setProperty("log4j.configurationFile", "config/log4j.xml");
I'm using a relative path to a folder named config that contains log4j.xml. An absolute path is not recommended, but may work as well.
Just be sure to set this before making any calls to log4j, including any log4j config settings or static method calls!
System.setProperty("log4j.configurationFile", "config/log4j.xml");
final Logger log = Logger.getLogger(Main.class);
log.info("Starting up");
I didn't specify the log4j path in the ini file, only placed log4j.xml file at the same place the jar was placed.
Also without specify the
System.setProperty("log4j.configurationFile", "config/log4j.xml");
In the Java project it was stored in (src/main/resources) and will be included in the jar, but it will not be that one used if placed outside the jar.
My site is structured in this way:
Root Directory
Arcade
default.aspx
web.config
default.aspx
web.config
I have a method Method1() which accesses:
System.Configuration.ConfigurationManager.AppSettings["Total_Unique_Plays_Required_For_High_Score_Board"]
This value exists in the root/Arcade/Web.config file but not in the root/web.config file.
When I execute Method1() from a page in the /arcade directory it works fine. However, when I execute this method as a timed event from global.asax it searches for the value in the root web.config file and throws a System.NullException.
Does anyone know how I can specify to search for the value in the root/arcade/web.config file and not the root/web.config file?
You can open the web.config file first.
So calling this will load your child file; notice you give the path to the folder containing the web.config, not the actual config file.
var config = WebConfigurationManager.OpenWebConfiguration("~/Arcade");
You can now get your values, like:
string MyValue = config.AppSettings.Settings["MySetting"].Value;
You can also get the list of app settings by calling:
KeyValueConfigurationCollection appSettings = config.AppSettings.Settings;
I have the following code to read the 'loggingConfiguration' from web.config file that is using EntLib 4.0
Configuration entLibConfig =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration
(#"/Web.config");
LoggingSettings loggingSettings =
(LoggingSettings)entLibConfig.GetSection(LoggingSettings.SectionName);
The loggingSettings object is null after the 2nd line executes.
Any suggestions on what is going wrong here?
ExeConfigurationFileMap exc = new ExeConfigurationFileMap();
exc.ExeConfigFilename = #"Web.exe.config";
Configuration _config = ConfigurationManager.OpenMappedExeConfiguration(exc,ConfigurationUserLevel.None);
LoggingSettings log = _config.GetSection("loggingConfiguration") as LoggingSettings;
Try this, it works for me.
The reason why you get null returned for LoggingSettings is that there is no LoggingSettings configured in the web.config that you are opening. This is probably because the path specified is incorrect.
I have a web appliation set up with 2 web.configs: The first in the root and the second in a Config folder.
/Root
web.config
/Root/Config
web.config
The web.config in the Config folder contains the LoggingSettings. The code to read the LoggingSettings from a page that is not located in the Config folder is:
Configuration entLibConfig =
WebConfigurationManager.OpenWebConfiguration(#"~/Config");
LoggingSettings loggingSettings =
(LoggingSettings)entLibConfig.GetSection(LoggingSettings.SectionName);
This should work in the Development Web Server as well as IIS.