简体   繁体   English

Castle Windsor测井拦截器示例随附任何源代码吗?

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

This is a great wiki article: http://docs.castleproject.org/Windsor.Introduction-to-AOP-With-Castle.ashx 这是一篇很棒的Wiki文章: http : //docs.castleproject.org/Windsor.Introduction-to-AOP-With-Castle.ashx

However, it is missing code for the DataContractSerialize. 但是,它缺少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 小号

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: 好吧,我认为扬·威尔逊(Jan Wilson)忽略了这一点,因为这对于他介绍AOP来说不是必需的,并且由于有多种方法可以序列化/转储数据,因此您可以在此处阅读:

http://www.danrigsby.com/blog/index.php/2008/03/07/xmlserializer-vs-datacontractserializer-serialization-in-wcf/ 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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM