Custom / Nested XML Settings in ServiceConfiguration.cscfg

We are trying to implement some dynamically tunable logging in our Azure application, and we use corporate libraries for this, which works fine, but the XML code needed to facilitate this is more complicated than just setting the "appSetting" style which is ServiceConfiguration.cscfg, apparently agrees that he needs nested xml nodes,

eg.

<configSections> <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" /> </configSections> 

which is allowed (skip formatting in this window, please):

 <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General"> <listeners> <add listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" type="OurSolution.Common.AzureDiagnosticTraceListener, Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="AzureDiagnosticTraceListener" /> </listeners> <formatters> <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}" name="Text Formatter" /> </formatters> <categorySources> <add switchValue="All" name="General"> <listeners> <add name="AzureDiagnosticTraceListener" /> </listeners> </add> </categorySources> </loggingConfiguration> 

I see no way to trick ServiceDefinition or ServiceConfiguration files into accepting this, although if I could see a way to tell corporate libraries to use the ServiceConfiguration file, which I can do in app.config.

Why are we trying to solve this so that we can dynamically configure logging parameters, i.e. Change from No logging to Verbose without the need for redeployment, which proves the complexity and inappropriateness in our real application, which only recently went on the air, so there may still be an odd error; -)

Any thoughts would be greatly appreciated. Best regards Kindo Malay

+6
logging azure enterprise-library
source share
2 answers

Other parameters:

  • Base64 encoding for arbitrary configurations and put them in cscfg value
  • (my favorite) Just save additional configs in the repository or blob database (makes life easier for deployment management).
+1
source share

Currently, ServiceConfiguration files are limited to the basic structure <Setting name="foo" value="bar" /> .

But the value is simply just a string value. What I did when I needed something more expressive was to put the XML as a string in the parameter value, and then deserialize it into XML when I read it. This makes the configuration file pretty ugly when you edit it directly, because it encodes all the XML in the settings, but it works.

If we just look at your listeners section to keep the example small:

 <listeners> <add listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" type="OurSolution.Common.AzureDiagnosticTraceListener, Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="AzureDiagnosticTraceListener" /> </listeners> 

This can be placed in a ServiceConfiguration file, similar to:

 <Setting name="Logging" value="&lt;listeners&gt;&lt;add listenerDataType=&quot;Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot; type=&quot;OurSolution.Common.AzureDiagnosticTraceListener, Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&quot; name=&quot;AzureDiagnosticTraceListener&quot; /&gt;&lt;/listeners&gt;" /> 

The easiest way to do this is to take the source XML, replace all tabs and carriage returns, and update the settings through the properties section of the cloud project.

Changing this parameter after its deployment is not completely direct, but feasible.

+1
source share

All Articles