This is a mirror of official site: http://jasper-net.blogspot.com/

LoggingBehavior - How to Connect Log-prints with the WCF Operation's Details, using a Simple Behavior

| Sunday, August 21, 2011
Introduction

When developing WCF services, we sometimes want to log some entries about our operations. We want to know that our operation has been called and, which parameters had been sent to it. We want to know that our operation has been ended successfully (if it has) and, what is the result. We want to know which errors occurred during our operation and, which parameters had been sent to the operation that cause the error.

Usually, for achieving this goal, I used to write code snippets like this:

WriteToLog(string.Format("MyOperation called. param1={0}, param2={1}", param1, param2));

or, when logging an error, in spite of the main information is the error reason, in order to connect it to the operation and its parameters, I needed to write something like this:

WriteToLog(string.Format("Error occurred in MyOperation.\n Parameters: param1={0},
param2={1}\n Error reason: some reason.", param1, param2));.

OK, this isn't such a big deal when you have 2 or 3 native parameters. But, if you have some complex parameters that maybe contain some collections of other complex classes, you can waste a lot of screens of code, only for log prints. Since I got tired of doing that any time I need logs, I decided to write a behavior that simplifies this task.


Read more: Codeproject
QR: ConvertNumberIntoWords.aspx

Posted via email from Jasper-net

0 comments: