How to log message in 'messageTemplate' field in validation section of web.config
-
lundi 30 avril 2012 09:54
Hi,
I am using Enterprise Library 5.0 and trying to use Validation block. In case of validation fails the log message displayed is something like bellow message:
" Message : Parameter validation failed "
I want to log message in 'message template' field in web.config file.
Please assist me.
Bellow is given 'validation' section in web.config
<validation>
<type name="MusicStore.Classical" defaultRuleset="Classical RuleSet"
assemblyName="MusicStore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<ruleset name="Classical RuleSet">
<properties>
<property name="Name">
<validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.NotNullValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
messageTemplate="Album Name can not be empty"
name="Not Null Validator" />
<validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
upperBound="20" lowerBound="10" lowerBoundType="Inclusive" upperBoundType="Ignore"
messageTemplate="Album name should be at least one character long"
name="String Length Validator" />
</property>
</properties>
</ruleset>
</type>
</validation>- Modifié Fusion Coder lundi 30 avril 2012 09:55
Toutes les réponses
-
mardi 1 mai 2012 08:13
Thanks to all, I got the solution,
In case we using Policy injection and used validation call handler for a perticular member type matching rule, then if validation fails, It will throw an exception of type 'ArgumentValidationException' which contain a property (ValidationResults) coantaining collection of validation results
So in catch block we can iterate through validation results and get the value in message template field as given bellow:
catch (ArgumentValidationException ex)
{
ValidationResults results = ex.ValidationResults;
foreach (var item in results)
{
Console.WriteLine(item.Message);
}
Console.Read();}
- Marqué comme réponse Mike FengMicrosoft Contingent Staff, Moderator mardi 1 mai 2012 10:45
-
mardi 1 mai 2012 10:45Modérateur
Hi bharat.
Congratulations.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

