Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't just tell ELMAH to do something with your connection string. What you can do, however, is tell ELMAH to call you back when it needs an <code>ErrorLog</code>, giving you more control at run-time. You can then read the encrypted connection string, decrypt it with your in-house function and return an SqlErrorLog initialized with it.</p> <p>To do this, you need to provide a method that is compatible with the <a href="http://code.google.com/p/elmah/source/browse/tags/REL-1.2/src/Elmah/ServiceCenter.cs#34" rel="nofollow"><code>ServiceProviderQueryHandler</code></a> delegate. Here's the definition:</p> <pre><code>public delegate IServiceProvider ServiceProviderQueryHandler(object context); </code></pre> <p>The implementation of the method must return an instance of an object that implements <code>IServiceProvider</code>. If you don't feel like writing one yourself to start with, you can get one for free from the .NET Framework. See <a href="http://www.google.com/url?sa=D&amp;q=http://msdn.microsoft.com/en-us/library/system.componentmodel.design.servicecontainer.aspx" rel="nofollow"><code>System.ComponentModel.Design.ServiceContainer</code></a>. The service provider's <code>GetService</code> must respond to requests for the <code>ErrorLog</code> type and you can then, for example, return a <code>SqlErrorLog</code> object that has been initialized with a connection string manipulated at runtime. Here's a possible implementation: </p> <pre class="lang-cs prettyprint-override"><code>var parent = ServiceCenter.Current; ServiceCenter.Current = context =&gt; { var container = new ServiceContainer(parent(context)); var connectionSettings = ConfigurationManager.ConnectionStrings["FOOBAR"]; var connectionString = Decrypt(connectionSettings.ConnectionString); var log = new SqlErrorLog(connectionString); container.AddService(typeof(ErrorLog), log); return container; } ; </code></pre> <p>This captures the current service point and installs your own instead. The lambda/delegate created pass on service requests to the captured service point when it cannot satisfy it directly, thus creating a chain. You tell ELMAH about your implementation by setting <code>ServiceCenter.Current</code> somewhere during the initialization of your application so that's where the above code will need to sit.</p> <p>Bear in mind that this is a very simple implementation but it should be good enough to get you started and optimize later if needed.</p> <p>Prior to this <a href="http://code.google.com/p/elmah/issues/detail?id=149" rel="nofollow">addition in 1.2</a>, the only way to do something similar required subclassing and other gymnastics and still yielded partial results. Now you just need to implement a method and hand it over to ELMAH and which simply responds to queries from ELMAH for objects based on their service type. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload