I thought this questions was trivial and that Enums were represented simply with an integer but I was surprised that it wasn't the case ! Here's what I have :
I have a custom config file that contains the following TraceEventType Property
[ConfigurationProperty("Severity")]
public TraceEventType Severity
{
get { return (TraceEventType)this["Severity"]; }
set { this["Severity"] = value; }
}
In my config file, I represented this property with the following value :
...
<FileLog Filename="Test"
Severity="1" />
The result : I got this :
System.Configuration.ConfigurationErrorsException: The value of the property 'Severity' cannot be parsed. The error is: The enumeration value must be one of the following: Critical, Error, Warning, Information, Verbose, Start, Stop, Suspend, Resume, Transfer.
You should be able to just use the names of your enum values in the config file, just like the error message states. For example:
<FileLog Filename="Test" Severity="Verbose" />
The System.Configuration classes will take care of parsing the enum for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With