none
write to IIS log file RRS feed

  • Question

  • How can I write to the IIS log file from a WCF service?  I see there is an HttpResponse.AppendToLog method available to asp.net server side code. Can I get access to the HttpResponse object of my server side WCF service code?

    Thanks,

    Thursday, February 18, 2010 9:35 PM

Answers

  • i found this in the reflector after drilling down into HttpResponse, to HttpWorkerRequest, to ISAPIWorkerRequest, and then back up to the derived ISAPIInProcessWorkerRequest.

    [DllImport("webengine.dll", CharSet=CharSet.Ansi)]
    internal static extern int EcbAppendLogParameter(IntPtr pECB, string logParam);
    I don't know what an ECB pointer is.. so that probably won't do any good.


    On an easier note have you tried:
    HttpContext.Current.Response.AppendToLog(value);

    James Peckham CSM, CSP, CAPM Developer and Agilist http://www.jamespeckham.com
    • Marked as answer by Steve Richter Tuesday, February 23, 2010 11:49 PM
    Friday, February 19, 2010 2:35 AM
  • Hi Steve,

    As James suggested, you can use HttpContext.Current.Response to access the HttpResponse object assciated with each ASP.NET worker thread. However, if you want to access ASP.NET runtime objects in WCF code, you need to first turn on the ASP.NET Compatibility mode:


    #ASP.NET Compatibility Mode
    http://blogs.msdn.com/wenlong/archive/2006/01/23/516041.aspx



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Steve Richter Tuesday, February 23, 2010 11:49 PM
    Monday, February 22, 2010 6:35 AM
    Moderator

All replies

  • i found this in the reflector after drilling down into HttpResponse, to HttpWorkerRequest, to ISAPIWorkerRequest, and then back up to the derived ISAPIInProcessWorkerRequest.

    [DllImport("webengine.dll", CharSet=CharSet.Ansi)]
    internal static extern int EcbAppendLogParameter(IntPtr pECB, string logParam);
    I don't know what an ECB pointer is.. so that probably won't do any good.


    On an easier note have you tried:
    HttpContext.Current.Response.AppendToLog(value);

    James Peckham CSM, CSP, CAPM Developer and Agilist http://www.jamespeckham.com
    • Marked as answer by Steve Richter Tuesday, February 23, 2010 11:49 PM
    Friday, February 19, 2010 2:35 AM
  • Hi Steve,

    As James suggested, you can use HttpContext.Current.Response to access the HttpResponse object assciated with each ASP.NET worker thread. However, if you want to access ASP.NET runtime objects in WCF code, you need to first turn on the ASP.NET Compatibility mode:


    #ASP.NET Compatibility Mode
    http://blogs.msdn.com/wenlong/archive/2006/01/23/516041.aspx



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Steve Richter Tuesday, February 23, 2010 11:49 PM
    Monday, February 22, 2010 6:35 AM
    Moderator