0

I just want to start by saying that I've done a lot of research but couldn't find an answer, hence the post.

I'm adding user settings functionality to my app which works as a plugin inside a common off the shelf program for architecture (called Autodesk Revit). The main project (let's call it MainProj) has several dependencies including a project that handles logging and usage (let's call it Loggers). I created a Settings file inside the Loggers project with the goal to have users change the logging level from Error to Debug when there are issues so I can ask them to make the change and send me the log.

The issue I'm facing is that when I change the log level directly inside the config file and re-run the command from within Revit, the change doesn't get translated into the log, as if the log level is somehow compiled during design and is never changed.

I actually tried to reproduce the problem in a simpler way and created a little console program and I'm facing the same issue. Below is the code from the Loggers project.

namespace Loggers
{
    public static class Logger
    {
        public static string RunMe()
        {
            if (Properties.Settings.Default.LogMode == "Debug") { return "DEBUG"; }
            else return "NOTHING";
        }
    }
}

I then changed the LogMode property from Debug to anything else in the config file but the console kept on returning DEBUG.

static void Main(string[] args)
{
    Console.WriteLine(Logger.RunMe());
    Console.Read();
}

I also tried changing the setting from user to application and editing its value in the config file and re-running the command but the outcome was the same.

Any help would be very much appreciated. I've been stuck on this for a while. Thank you.

floretti
  • 31
  • 5
  • 1
    The settings must be in the App.config of the hosting executable. So you have the LogMode settings in the conf for the Autodesk Revit executable? Or is this a user setting? – Ralf Sep 26 '22 at 11:49
  • 1
    `Properties.Settings.Default` depends on the version of windows. ~ https://stackoverflow.com/q/982354/1462295 – BurnsBA Sep 26 '22 at 13:48
  • @Ralf Thank you but Autodesk Revit is an off the shelf product, I didn't make it so I'm guessing I can't create an App.config for it. I just made the plugin that uses its API to perform some tasks. – floretti Sep 26 '22 at 22:05
  • @BurnsBA Thanks for sharing that. What I'm getting from it is that I shouldn't be editing the config file manually, especially the app.config since the application would look for an user.config for user settings. The problem is that the user.config doesn't seem to exist until the first user setting is changed. – floretti Sep 26 '22 at 22:25
  • @floretti presumably you can simply create an app.config by hand it just needs to live directly besides the executable and needs the correct name. The framework will then pick it up. – Ralf Sep 27 '22 at 07:41
  • @Ralf Thank you, I had no idea that was possible. This would be my next step if I didn't found the issue, which I did and I'll post it here in case anyone else faces the same. – floretti Sep 27 '22 at 22:10
  • @floretti I glad to know you've found the solution to resolve this issue! Please consider accepting it as an answer to change its status to Answered. See [can I answer my own question..](https://stackoverflow.com/help/self-answer), Just a reminder :) – Jiale Xue - MSFT Sep 28 '22 at 02:23

1 Answers1

0

Thanks to @BurnsBA, the link you shared had comments saying that the user.config lives in a different folder and it's not created until the user changes a setting. This made me understand that there wasn't a point in manually editing the app.config and expect the settings to work.

I then did some testing by creating a simple form with a checkbox linked to the Property I wanted to change and the user.config file gets created straight after I call the Save() method on the Properties.

private void btnOK_Click(object sender, EventArgs e)
{
    if (chkDebugMode.Checked == true)
        Loggers.Properties.Settings.Default.LogMode = "Debug";
    else Loggers.Properties.Settings.Default.LogMode = "Error";

    Loggers.Properties.Settings.Default.Save();
    Close();
}
floretti
  • 31
  • 5