Search code examples
.net-coreconfigurationazure-functionsenvironment-variablesibm-mq

Tracing configuration for IBM MQ client does not seem to get overridden by Environment variables


I'm using the IBMMQDotnetClient NuGet package (9.3.3) and as stated here, you should be able to override settings defined in mqclient.ini by using environment variables. This does not seem to work when I run my app, an Azure Function app, locally.

My mqclient.ini, located in the root of my app, contains this:

    Trace:
        MQDotnetTraceLevel=2
        MQDotnetTracePath=C:\home\mq_traces

This works fine, when I attempt to connect to my MQ host I can see .TRC files being created in that directory. But when I try to override these settings through my launchSettings.json, nothing changes. launchSettings.json:

{
  "profiles": {
    "FunctionAppWithMq": {
      "commandName": "Project",
      "commandLineArgs": "--port 7222",
        "launchBrowser": false,
        "environmentVariables": {
            "MQDotnetTraceLevel": "1",
            "MQDotnetTracePath": "C:\\home\\traces_from_environment_variables"
        }
    }
  }
}

The trace files are still being generated in my mq_traces folder. I know the environment settings are set correctly; when I log the values using Environment.GetEnvironmentVariable() in one of my activity functions, I get the configured values from my launchSettings.json.

How can I get the MQ client to use my environment variables?

I want to be able to control tracing through configuration, not through an .ini file. But when I completely remove the ini file from my Azure function app, I get this exception:

Exception: System.TypeInitializationException: The type initializer for 'IBM.WMQ.MQQueueManager' threw an exception.
 ---> System.IO.FileNotFoundException: Error reading the  directory.
   at System.IO.FileSystemWatcher.StartRaisingEvents()
   at IBM.WMQ.MQClientCfg.CheckForMqclientIniFileChanges()
   at IBM.WMQ.Nmqi.NmqiEnvironment..ctor(NmqiPropertyHandler nmqiPropertyHandler)
   at IBM.WMQ.Nmqi.NmqiFactory.GetInstance(NmqiPropertyHandler properties)
   at IBM.WMQ.MQQueueManager..cctor()

(this exception does not occur locally)


Solution

  • According to the docs here the environment variables used to control tracing are MQDOTNET_TRACE_ON, MQTRACELEVEL and MQTRACEPATH not MQDotnetTraceLevel and MQDotnetTracePath.