Set app.config value to Environment.UserName
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 --> &l开发者_运维百科t;add key="from" value="MATRIX@Exception.Handler"/>
Is there a way to have the value set to Environment.Username + '@ourcompany.org
.
As a side note this is an internal app only.
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.
This is not possible.
You will need to modify the code that reads the value.
精彩评论