Is there any source code that goes along with the Castle Windsor Logging Interceptor Example?

StackOverflow https://stackoverflow.com/questions/14055432

Frage

This is a great wiki article: http://docs.castleproject.org/Windsor.Introduction-to-AOP-With-Castle.ashx

However, it is missing code for the DataContractSerialize. I am pretty sure that this method is fairly simple, but, for completeness, it would be great to have an example.

Does one exists? Or, is there a working example of the code?

Thanks

S

War es hilfreich?

Lösung

Well, I think Jan Wilson left this out, since it's unessential for his AOP introduction and because there are several ways to serialize/dump data, you may read about it here:

http://www.danrigsby.com/blog/index.php/2008/03/07/xmlserializer-vs-datacontractserializer-serialization-in-wcf/

So you could simply use the following:

private static void DataContractSerialize(object argument, Type argumentType)
{
    var settings = new XmlWriterSettings { Indent = true, ConformanceLevel = ConformanceLevel.Auto };
    var serializer = new DataContractSerializer(argumentType);
    using (XmlWriter xml = XmlWriter.Create(YOUR_PATH_TO_LOGFILE_CONST_STRING, settings))
    {
        xml.WriteStartDocument();
        serializer.WriteObject(xml, argument);
    }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top