2011-01-08 9 views
6

私はWebサービスのセットを持っており、トレースレイヤーを追加したいと思います。 私は多くの人がいるので、各Webサービスを変更したくありません。 Webサービスに入力するたびにログを書きたい、Webサービスの名前とパラメータ。webservices trace/log

どうすればよいですか?

P.S.私はasp.netとC#を使用しています。

EDIT: Webサービスをラップしたいのは、最初にログ(..)があるためです。

+0

"私は多くのことがあるので、各Webサービスを変更したくありません" - おそらくあなたはAOPを使うことができます。 ... –

+2

サーバーアクセスログを使用できます –

+0

SoapExtensionクラスのMSDNドキュメントを参照してください。ロギングの例があります。 –

答えて

6

一般的な方法は、SOAP拡張を挿入することです。そこから、生のSOAPですべての要求/応答パケットを傍受することができます。このサンプルは実装方法を示しており、その動作方法と構成方法について説明しています。

サンプル:

http://msdn.microsoft.com/en-us/library/system.web.services.protocols.soapextension.aspx

説明:

http://msdn.microsoft.com/en-us/library/esw638yk(vs.71).aspx

構成:

http://msdn.microsoft.com/en-us/library/b5e8e7kk(v=vs.71).aspx

<configuration> 
<system.web> 
    <webServices> 
    <soapExtensionTypes> 
     <add type="{Type name}, {Assembly}" priority="1" group="0" /> 
    </soapExtensionTypes> 
    </webServices> 
</system.web> 
</configuration> 
+0

ええ、私はそれは "一般的に受け入れられた方法"ではありません。それは方法です! – phillip

+0

@phillip十分に公正で、「共通」に変更されました。 –

0

私はOpen source web services frameworkを維持しています。これは、すべてのWebサービスを基本クラスから継承し、独自のログを作成することで簡単に達成できます。ここで

は私が redisにすべての例外のための分散ローリングログを維持 example of a base-classである - 非常に高速のNoSQLデータストア:私はグローバルになり、通常のASP.NET Webサービスフレームワークのためにそれ以外の場合は

public object Execute(TRequest request) 
{ 
    try 
    { 
     //Run the request in a managed scope serializing all 
     return Run(request); 
    } 
    catch (Exception ex) 
    { 
     return HandleException(request, ex); 
    } 
} 

protected object HandleException(TRequest request, Exception ex) 
{ 
    var responseStatus = ResponseStatusTranslator.Instance.Parse(ex); 

    if (EndpointHost.UserConfig.DebugMode) 
    { 
     // View stack trace in tests and on the client 
     responseStatus.StackTrace = GetRequestErrorBody() + ex; 
    } 

    Log.Error("ServiceBase<TRequest>::Service Exception", ex); 

    //If Redis is configured, maintain rolling service error logs in Redis (an in-memory datastore) 
    var redisManager = TryResolve<IRedisClientsManager>(); 
    if (redisManager != null) 
    { 
     try 
     { 
      //Get a thread-safe redis client from the client manager pool 
      using (var client = redisManager.GetClient()) 
      { 
       //Get a client with a native interface for storing 'ResponseStatus' objects 
       var redis = client.GetTypedClient<ResponseStatus>(); 

       //Store the errors in predictable Redis-named lists i.e. 
       //'urn:ServiceErrors:{ServiceName}' and 'urn:ServiceErrors:All' 
       var redisSeriviceErrorList = redis.Lists[UrnId.Create(UrnServiceErrorType, ServiceName)]; 
       var redisCombinedErrorList = redis.Lists[UrnId.Create(UrnServiceErrorType, CombinedServiceLogId)]; 

       //Append the error at the start of the service-specific and combined error logs. 
       redisSeriviceErrorList.Prepend(responseStatus); 
       redisCombinedErrorList.Prepend(responseStatus); 

       //Clip old error logs from the managed logs 
       const int rollingErrorCount = 1000; 
       redisSeriviceErrorList.Trim(0, rollingErrorCount); 
       redisCombinedErrorList.Trim(0, rollingErrorCount); 
      } 
     } 
     catch (Exception suppressRedisException) 
     { 
      Log.Error("Could not append exception to redis service error logs", suppressRedisException); 
     } 
    } 

    var responseDto = CreateResponseDto(request, responseStatus); 

    if (responseDto == null) 
    { 
     throw ex; 
    } 

    return new HttpResult(responseDto, null, HttpStatusCode.InternalServerError); 
} 

.asaxイベント、具体的には新しいリクエストが来るたびに起動する 'Application_BeginRequest'イベント

+3

@mythz:開示してくださいServiceStackへの接続。オープンソースのプロジェクトでも、このような勧告を行うことは依然として迷惑メールになります。私がServiceStackを推薦したのは初めてです。他の問題の中で、あなたはこの問題を解決するためにどのように使用されるかを示していません。 –

+0

私は、他のWebサービスフレームワークを使用していれば、どのように簡単に達成できるかについての推奨を行っています。元の質問は決してそれが特定されたことはありません。私の元の答えは、彼の目標を達成させるGlobal.asaxイベントの場所も提供しました。なぜあなたは自分自身でより良い答えを提供しないのですか?個人的には、特定のWebサービス技術/フレームワークへのあなたの仕様が、あなたの行動の主な動機であると思います。 – mythz

+1

@mythz:ASP.NET Webサービスを指定していたように見えました。それと私が以前にサービス業のことを聞いたことがないという事実は、あなたに丁寧に尋ねて開示することと何か関係があるかもしれません。そうしていただきありがとうございます。私はあなたがこのフレームワークをお勧めするたびにこれを行うことを願っています。また、あなたのフレームワークがこの問題をどのように解決するかを実際に示すことをお勧めします。 –

0

プロジェミング言語が重要でない場合は、Apache Synapseをプロキシとしてサービスの前に置くことができます。クライアントはSynapseに要求を送信し、Synapseはその要求を元のサービスに委譲します。プロキシは、ロギングなど、リクエストを中間で実行するように設定できます。

詳細については、以下のリンクを参照してください。

http://synapse.apache.org/Synapse_Configuration_Language.html#proxy
http://synapse.apache.org/Synapse_Configuration_Language.html#send
http://synapse.apache.org/Synapse_Configuration_Language.html#log

次の例の組み合わせがあなたのために働くことができます:

http://synapse.apache.org/Synapse_Samples.html#Sample0
http://synapse.apache.org/Synapse_Samples.html#ProxyServices

例えば:

<definitions xmlns="http://ws.apache.org/ns/synapse" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://ws.apache.org/ns/synapse http://synapse.apache.org/ns/2010/04/configuration/synapse_config.xsd"> 

<proxy name="StockQuoteProxy"> 
    <target> 
     <endpoint> 
      <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> 
     </endpoint> 
     <outSequence> 
      <!-- log all attributes of messages passing through --> 
      <log level="full"/> 

      <!-- Send the message to implicit destination --> 
      <send/> 
     </outSequence> 
    </target> 
    <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/> 
</proxy> 

+0

でお気軽にお問い合わせください。私はasp.Netを使用しています。私はApache Synapseのプッシュは良い考えだとは思わない。私は世話をしなければならない別の "システム"は必要ありません。不要な統合が気に入らない - .NETの領域には解決策があると思う。 – Naor

0

いかがwriting your own HttpModule?これは、既存のWebサービスコードに触れる必要性を否定するでしょう。各web.configファイルにモジュールを追加するだけで済みます。

+0

あなたのアプローチと同じgloba.asaxを使用できます。あなたのアプローチはすべての要求を記録します。 jsファイル、cssファイル、および画像の要求さえも。私はそれを必要としません。 – Naor

1

グローバルアプリケーションクラスGlobal.asaxファイルをプロジェクトに追加し、ロギングロジックをApplication_BeginRequest()メソッドに追加します。 送信者オブジェクトには、HTTPリクエストとパラメータが含まれます。 .asmx要求だけをフィルタリングしてログに記録することができます。

protected void Application_BeginRequest(object sender, EventArgs e) 
    { 

    } 
+0

ロギングロジックの例がありますか?さらに、これはすべての要求を記録します。 jsファイル、cssファイル、および画像の要求さえも。私はそれを必要としません。 – Naor

+0

@Naor :((System.Web.HttpApplication)(sender))。要求は、あなたが検査できるSystem.Web.HttpRequestオブジェクトを提供します。 .asmxで終わるURLにPOSTをチェックすることができます。あなたはあなたの条件付きチェックと一致する要求だけをログに記録します。 – tawman

+0

更新を参照してください。 – Naor

1

EDIT--
PostSharpに試してみてください。この機能を利用する最も簡単な方法です。後輩のために私は以下の投稿を残しておきますが、それを無視してPostSharpを使います。あなたのWebサービスは、WCFをしている場合


は、あなたはhttp://msdn.microsoft.com/en-us/magazine/cc163302.aspxをチェックアウトする必要があります。

途中の各ステップで、プラグイン可能な拡張ポイントを提供します。これらの拡張ポイントを使用して、メッセージまたはパラメータの検証、メッセージのログ、メッセージの変換など、さまざまなカスタム動作を実装できます。

これは、間違いなくWCFサービスに行く方法です。それ以外の場合、それらが単なるWebサービスであれば、Unityフレームワークと接続とインターセプタを使用して同じことを行うことができます。

+0

私はPostSharpとは何か分かりません。私はこの目的のためにツールを購入したくありません。 – Naor

+0

彼らはコミュニティ版を持っており、スニペット/例はあなたが達成したいものを正確に示しています。 – phillip

-1

これはあなたが探しているものであれば、私は「」

後にそれはあなたがマイクロソフトを使用して読み取ることができるようになります非常に大規模なログを作成するだけで、あなたにWCFの設定ファイルをこのを追加し、知りませんサービストレースビューア

<system.diagnostics> 
    <sources> 
    <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing"> 
    <listeners> 
    <add type="System.Diagnostics.DefaultTraceListener" name="Default"> 
     <filter type="" /> 
    </add> 
    <add name="ServiceModelMessageLoggingListener"> 
     <filter type="" /> 
    </add> 
    </listeners> 
    </source> 
    <source name="System.ServiceModel" switchValue="Warning, ActivityTracing" 
    propagateActivity="true"> 
    <listeners> 
    <add type="System.Diagnostics.DefaultTraceListener" name="Default"> 
     <filter type="" /> 
    </add> 
    <add name="ServiceModelTraceListener"> 
     <filter type="" /> 
    </add> 
    </listeners> 
    </source> 
    </sources> 
    <sharedListeners> 
    <add initializeData="C:\ServiceLog.svclog" 
    type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
    name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp"> 
    <filter type="" /> 
    </add> 
    <add initializeData="C:\Tracelog.svclog" 
    type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
    name="ServiceModelTraceListener" traceOutputOptions="Timestamp"> 
    <filter type="" /> 
    </add> 
    </sharedListeners> 
</system.diagnostics> 
+1

-1:彼はASMX Webサービスを使用しています。 –