托管在IIS上的wcf,在启动的时候,写log

https://blogs.msdn.microsoft.com/wenlong/2006/01/11/how-to-initialize-hosted-wcf-services/

Using AppInitialize

The above global.asax does not work for non-HTTP protocols such as net.tcp and net.pipe that is supported by the Windows Activation Service (WAS) on Windows Vista. There is no protocol-agnostic counterpart for HttpApplication in this case.

 

Fortunately, ASP.NET provides a simple hook that works in a protocol agnostic way. The hook is based on the following AppInitialize method:

    public static void AppInitialize();

This method can be put in any type that is defined in a C# file in the application’s App_Code directory. When the AppDomain is started, ASP.NET checks whether there is a type that has such as method (exact name and signature) and invokes it. Note that the AppInitialize method can be only defined once and it has to be in a code file instead of a pre-compiled assembly.

将此文件集成到wcf发布的library

右键选中文件,然后properties,将BuildAction设置为Compile

原文地址:https://www.cnblogs.com/chucklu/p/8795429.html