views:

137

answers:

2

I have an Exception Handler that email our Help Desk software whenever there is an error. All properties for the Mailer are handled in app.config. One of which looks like this --> <add key="from" value="[email protected]"/>

Is there a way to have the value set to Environment.Username + '@ourcompany.org.

As a side note this is an internal app only.

A: 

This is not possible.
You will need to modify the code that reads the value.

SLaks
+1  A: 

Use the Macro pattern. Set the value to be [User]@Exception.Handler, then wrap it in a helper method. Add String.Replace("[User]", Environment.Username) in the helper, and you are good to go.

Always wrap configuration values in helper method. This allows you to convert from string to other type, check for invalid values, substitute defaults, etc. Configuration files frequently are incorrect or mangled causing difficult-to-diagnose runtime errors.

Jennifer Zouak