Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've used the interceptor tecnique to log all WCF call. You need to add some parameters to your appender (controller, action, user, datain, dataout) Hope this help</p> <pre><code>public interface IOpenUserName { string UserName { get; set; } } [AttributeUsage(AttributeTargets.Method)] public class LogWcfAttribute : Attribute { } public class LogWcfInterceptor : IInterceptor { private readonly ILogger _logger; public LogWcfInterceptor(ILogger logger) { _logger = logger; } public void Intercept(IInvocation invocation) { if (WcfHelper.HasLogWcfAttribute(invocation.MethodInvocationTarget)) { Exception exception = null; var openUser = (IOpenUserName) invocation.InvocationTarget; log4net.LogicalThreadContext.Properties["controller"] = invocation.InvocationTarget.GetType().Name; log4net.LogicalThreadContext.Properties["action"] = invocation.MethodInvocationTarget.Name; log4net.LogicalThreadContext.Properties["user"] = openUser != null ? openUser.UserName : string.Empty; log4net.LogicalThreadContext.Properties["datain"] = SerializeObject(invocation.Arguments); try { invocation.Proceed(); } catch (Exception ex) { exception = ex; } finally { log4net.LogicalThreadContext.Properties["dataout"] = SerializeObject(invocation.ReturnValue); _logger.Debug("OPENOTA", exception); } if (exception != null) throw exception; } else { invocation.Proceed(); } } public static string SerializeObject(object toSerialize) { if (toSerialize == null) return string.Empty; var xmlSerializer = new XmlSerializer(toSerialize.GetType()); var textWriter = new StringWriter(); xmlSerializer.Serialize(textWriter, toSerialize); return textWriter.ToString(); } } public static class WcfHelper { public static bool HasLogWcfAttribute(MethodInfo methodInfo) { return methodInfo.IsDefined(typeof(LogWcfAttribute), false); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload