<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Logging &#8211; شرکت سهند رایانه کویر یزد ( Sahand Company ) | طراحی وب سایت یزد | برنامه نویسی | اندروید | موبایل | نرم افزار | هاست | دامنه</title>
	<atom:link href="https://sahand-kavir.com/tag/logging/feed/" rel="self" type="application/rss+xml" />
	<link>https://sahand-kavir.com</link>
	<description>تولید نرم افزارهای اداری - طراحی وب سایت های شرکتی ، شخصی ، خبری ، فروشگاهی - طراحی گرافیک و بروشور و کاتالوگ و ست اداری</description>
	<lastBuildDate>Wed, 28 Jan 2015 04:29:47 +0000</lastBuildDate>
	<language>fa-IR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://sahand-kavir.com/storage/2016/11/logo-71x73.png</url>
	<title>Logging &#8211; شرکت سهند رایانه کویر یزد ( Sahand Company ) | طراحی وب سایت یزد | برنامه نویسی | اندروید | موبایل | نرم افزار | هاست | دامنه</title>
	<link>https://sahand-kavir.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>ثبت جزئیات استثناهای Entity framework توسط ELMAH</title>
		<link>https://sahand-kavir.com/entity-framework-exceptional-detail-by-elmah/</link>
					<comments>https://sahand-kavir.com/entity-framework-exceptional-detail-by-elmah/#respond</comments>
		
		<dc:creator><![CDATA[sahand]]></dc:creator>
		<pubDate>Wed, 28 Jan 2015 04:29:47 +0000</pubDate>
				<category><![CDATA[برنامه نویسی]]></category>
		<category><![CDATA[Command]]></category>
		<category><![CDATA[ELMAH]]></category>
		<category><![CDATA[Entity framework]]></category>
		<category><![CDATA[IDbCommandInterceptor]]></category>
		<category><![CDATA[Interceptorاستثناهای EF]]></category>
		<category><![CDATA[Logging]]></category>
		<category><![CDATA[Raise]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[استثناهای]]></category>
		<category><![CDATA[اینترفیس]]></category>
		<category><![CDATA[پیاده سازی سفارشی]]></category>
		<guid isPermaLink="false">http://sahand-kavir.com/entity-framework-exceptional-detail-by-elmah/</guid>

					<description><![CDATA[<p>در حین بروز استثناهای Entity framework، می‌توان توسط ابزارهای Logging متنوعی مانند ELMAH، جزئیات متداول آن‌ها را برای بررسی‌های آتی ذخیره کرد. اما این جزئیات فاقد SQL نهایی تولیدی و همچنین پارامترهای ورودی توسط کاربر یا تنظیم شده توسط برنامه هستند. برای اینکه بتوان این جزئیات را نیز ثبت کرد، می‌توان یک IDbCommandInterceptor جدید را [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sahand-kavir.com/entity-framework-exceptional-detail-by-elmah/">ثبت جزئیات استثناهای Entity framework توسط ELMAH</a> appeared first on <a rel="nofollow" href="https://sahand-kavir.com">شرکت سهند رایانه کویر یزد ( Sahand Company ) | طراحی وب سایت یزد | برنامه نویسی | اندروید | موبایل | نرم افزار | هاست | دامنه</a>.</p>
]]></description>
										<content:encoded><![CDATA[</p>
<p>در حین بروز استثناهای Entity framework، می‌توان توسط ابزارهای Logging متنوعی مانند ELMAH، جزئیات متداول آن‌ها را برای بررسی‌های آتی ذخیره کرد. اما این جزئیات فاقد SQL نهایی تولیدی و همچنین پارامترهای ورودی توسط کاربر یا تنظیم شده توسط برنامه هستند. برای اینکه بتوان این جزئیات را نیز ثبت کرد، می‌توان یک IDbCommandInterceptor جدید را طراحی کرد.</p>
<p>کلاس EfExceptionsInterceptor</p>
<p>در اینجا نمونه‌ای از یک پیاده سازی اینترفیس IDbCommandInterceptor را مشاهده می‌کنید. همچنین طراحی یک متد عمومی که می‌تواند به جزئیات SQL نهایی و پارامترهای آن دسترسی داشته باشد، در اینترفیس IEfExceptionsLogger ذکر شده‌است</p>
<p dir="ltr"><strong>public interface IEfExceptionsLogger</strong><br /><strong>{</strong><br /><strong> void LogException&lt;TResult&gt;(DbCommand command,</strong><br /><strong> DbCommandInterceptionContext&lt;TResult&gt; interceptionContext);</strong><br /><strong>}</strong></p>
<p><strong>using System.Data.Common;</strong><br /><strong>using System.Data.Entity.Infrastructure.Interception;</strong></p>
<p><strong>namespace ElmahEFLogger</strong><br /><strong>{</strong><br /><strong> public class EfExceptionsInterceptor : IDbCommandInterceptor</strong><br /><strong> {</strong><br /><strong> private readonly IEfExceptionsLogger _efExceptionsLogger;</strong></p>
<p><strong> public EfExceptionsInterceptor(IEfExceptionsLogger efExceptionsLogger)</strong><br /><strong> {</strong><br /><strong> _efExceptionsLogger = efExceptionsLogger;</strong><br /><strong> }</strong></p>
<p><strong> public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext&lt;int&gt; interceptionContext)</strong><br /><strong> {</strong><br /><strong> _efExceptionsLogger.LogException(command, interceptionContext);</strong><br /><strong> }</strong></p>
<p><strong> public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext&lt;int&gt; interceptionContext)</strong><br /><strong> {</strong><br /><strong> _efExceptionsLogger.LogException(command, interceptionContext);</strong><br /><strong> }</strong></p>
<p><strong> public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext&lt;DbDataReader&gt; interceptionContext)</strong><br /><strong> {</strong><br /><strong> _efExceptionsLogger.LogException(command, interceptionContext);</strong><br /><strong> }</strong></p>
<p><strong> public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext&lt;DbDataReader&gt; interceptionContext)</strong><br /><strong> {</strong><br /><strong> _efExceptionsLogger.LogException(command, interceptionContext);</strong><br /><strong> }</strong></p>
<p><strong> public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext&lt;object&gt; interceptionContext)</strong><br /><strong> {</strong><br /><strong> _efExceptionsLogger.LogException(command, interceptionContext);</strong><br /><strong> }</strong></p>
<p><strong> public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext&lt;object&gt; interceptionContext)</strong><br /><strong> {</strong><br /><strong> _efExceptionsLogger.LogException(command, interceptionContext);</strong><br /><strong> }</strong><br /><strong> }</strong><br /><strong>}</strong></p>
<p>تهیه یک پیاده سازی سفارشی از IEfExceptionsLogger توسط ELMAH</p>
<p>اکنون که ساختار کلی IDbCommandInterceptor سفارشی برنامه مشخص شد، می‌توان پیاده سازی خاصی از آن‌را جهت استفاده از ELMAH به نحو ذیل ارائه داد:</p>
<p dir="ltr"><strong>using System;</strong><br /><strong>using System.Data.Common;</strong><br /><strong>using System.Data.Entity.Infrastructure.Interception;</strong><br /><strong>using Elmah;</strong></p>
<p><strong>namespace ElmahEFLogger.CustomElmahLogger</strong><br /><strong>{</strong><br /><strong> public class ElmahEfExceptionsLogger : IEfExceptionsLogger</strong><br /><strong> {</strong><br /><strong> /// &lt;summary&gt;</strong><br /><strong> /// Manually log errors using ELMAH</strong><br /><strong> /// &lt;/summary&gt;</strong><br /><strong> public void LogException&lt;TResult&gt;(DbCommand command,</strong><br /><strong> DbCommandInterceptionContext&lt;TResult&gt; interceptionContext)</strong><br /><strong> {</strong><br /><strong> var ex = interceptionContext.OriginalException;</strong><br /><strong> if (ex == null)</strong><br /><strong> return;</strong></p>
<p><strong> var sqlData = CommandDumper.LogSqlAndParameters(command, interceptionContext);</strong><br /><strong> var contextualMessage = string.Format(&#8220;{0}{1}OriginalException:{1}{2} {1}&#8221;, sqlData, Environment.NewLine, ex);</strong></p>
<p><strong> if (!string.IsNullOrWhiteSpace(contextualMessage))</strong><br /><strong> {</strong><br /><strong> ex = new Exception(contextualMessage, new ElmahEfInterceptorException(ex.Message));</strong><br /><strong> }</strong></p>
<p><strong> try</strong><br /><strong> {</strong><br /><strong> ErrorSignal.FromCurrentContext().Raise(ex);</strong><br /><strong> }</strong><br /><strong> catch</strong><br /><strong> {</strong><br /><strong> ErrorLog.GetDefault(null).Log(new Error(ex));</strong><br /><strong> }</strong><br /><strong> }</strong><br /><strong> }</strong><br /><strong>}</strong></p>
<p dir="rtl">در اینجا شیء Command به همراه SQL نهایی تولید و پارامترهای مرتبط است. همچنین interceptionContext.OriginalException جزئیات عمومی استثنای رخ داده را به همراه دارد. می‌توان این اطلاعات را پس از اندکی نظم بخشیدن، به متد Raise مربوط به ELMAH ارسال کرد تا جزئیات بیشتری از استثنای رخ داده شده، در لاگ‌های آن ظاهر شوند.</p>
<p dir="rtl">استفاده از ElmahEfExceptionsLogger جهت طراحی یک Interceptor عمومی</p>
<p dir="ltr">public class ElmahEfInterceptor : EfExceptionsInterceptor<br /> {<br /> public ElmahEfInterceptor()<br /> : base(new ElmahEfExceptionsLogger())<br /> { }<br /> }</p>
<p dir="rtl">برای استفاده از ElmahEfExceptionsLogger و تهیه یک Interceptor عمومی، می‌توان با ارث بری از کلاس Interceptor ابتدای بحث شروع کرد و وهله‌ای از ElmahEfExceptionsLogger را به سازنده‌ی آن تزریق نمود (یکی از چندین روش ممکن). سپس برای استفاده از آن کافی است به ابتدای متد Application_Start فایل Global.asax.cs مراجعه و در ادامه سطر ذیل را اضافه نمود:</p>
<p dir="ltr">DbInterception.Add(new ElmahEfInterceptor());</p>
<p dir="rtl">پس از آن جزئیات کلیه استثناهای EF در لاگ‌های نهایی ELMAH به نحو ذیل ظاهر خواهند شد:</p>
<p dir="rtl"><img fetchpriority="high" decoding="async" class=" size-full wp-image-249" src="http://sahand-kavir.com/storage/2015/01/entity-framework-exceptional-detail-by-elmah_2.png" alt="entity-framework-exceptional-detail-by-elmah 2" width="637" height="408" srcset="https://sahand-kavir.com/storage/2015/01/entity-framework-exceptional-detail-by-elmah_2.png 820w, https://sahand-kavir.com/storage/2015/01/entity-framework-exceptional-detail-by-elmah_2-300x192.png 300w, https://sahand-kavir.com/storage/2015/01/entity-framework-exceptional-detail-by-elmah_2-768x492.png 768w" sizes="(max-width: 637px) 100vw, 637px" /></p>
<p dir="rtl"><img decoding="async" class=" size-full wp-image-250" src="http://sahand-kavir.com/storage/2015/01/entity-framework-exceptional-detail-by-elmah.png" alt="entity-framework-exceptional-detail-by-elmah" width="636" height="406" srcset="https://sahand-kavir.com/storage/2015/01/entity-framework-exceptional-detail-by-elmah.png 820w, https://sahand-kavir.com/storage/2015/01/entity-framework-exceptional-detail-by-elmah-300x192.png 300w, https://sahand-kavir.com/storage/2015/01/entity-framework-exceptional-detail-by-elmah-768x492.png 768w" sizes="(max-width: 636px) 100vw, 636px" /></p>
<p> <span id="more-251"></span> <img decoding="async" src="http://sahand-kavir.com/storage/2015/01/web-based-version-of-whatsapp.jpg"></p>
<p>The post <a rel="nofollow" href="https://sahand-kavir.com/entity-framework-exceptional-detail-by-elmah/">ثبت جزئیات استثناهای Entity framework توسط ELMAH</a> appeared first on <a rel="nofollow" href="https://sahand-kavir.com">شرکت سهند رایانه کویر یزد ( Sahand Company ) | طراحی وب سایت یزد | برنامه نویسی | اندروید | موبایل | نرم افزار | هاست | دامنه</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sahand-kavir.com/entity-framework-exceptional-detail-by-elmah/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
