0

I've used the solution from here for logging (and insert to DB) REST request successfully, now i have to do the same to WCF

        [LogApiRequest]
        public NadlanData GetNadlanData(decimal Id, KodFamilyEnum KodFamily)
        {
            ClsDalByTz objByTz = new ClsDalByTz();           
            return objByTz.getDataFromMF(Id, DateTime.Now.Year - 5, (decimal)KodFamily);       
        }

I've tried to do the same by adding [LogApiRequest] to the WCF function but it did not work.

How can i implement the same solution for WCF?

yanivz
  • 158
  • 1
  • 13

1 Answers1

0

The custom attribute - LogApiRequest - derives from System.Web.Http.Filters.ActionFilterAttribute. Action filter attributes are documented here - https://www.tutorialsteacher.com/webapi/web-api-filters and here - https://learn.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/controllers-and-routing/understanding-action-filters-cs.

The reason your attribute works in your web api is because asp.net or asp.net core processing pipeline supports calling custom code defined in user defined code - you are plugging custom feature in the processing pipeline. Know more about asp.net pipeline here - https://learn.microsoft.com/en-us/archive/msdn-magazine/2002/september/asp-net-request-processing-filtering-and-content-redirection

The reason it does not work with WCF is because that processing pipeline does not support customisation through HTTP filters. WCF has its own way of doing logging. Check out these links - https://learn.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/tracing/configuring-tracing and https://learn.microsoft.com/en-us/dotnet/framework/wcf/samples/tracing-and-message-logging

You will find yourself editing custom configuration files most of the time. I cannot give you a short attribute name or configuration script because it depends on type of WCF endpoint you are implementing, their name etc. The tracing and message logging link above contains some samples. Copy paste those configurations but edit file path and interface names based on what you have got code. That should work.

Amogh Sarpotdar
  • 544
  • 4
  • 15