<?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>C# Archives - Blog IT</title>
	<atom:link href="https://blogit.create.pt/category/dotnet/c/feed/" rel="self" type="application/rss+xml" />
	<link>https://blogit.create.pt/category/dotnet/c/</link>
	<description>Create IT blogger community</description>
	<lastBuildDate>Tue, 30 Jan 2024 18:30:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>Provision a database programmatically in Azure SQL database with a failover group</title>
		<link>https://blogit.create.pt/miguelisidoro/2024/01/24/provision-a-database-programmatically-in-azure-sql-database-with-a-failover-group/</link>
					<comments>https://blogit.create.pt/miguelisidoro/2024/01/24/provision-a-database-programmatically-in-azure-sql-database-with-a-failover-group/#respond</comments>
		
		<dc:creator><![CDATA[Miguel Isidoro]]></dc:creator>
		<pubDate>Wed, 24 Jan 2024 14:32:24 +0000</pubDate>
				<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Microsoft Azure]]></category>
		<category><![CDATA[azure]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">https://blogit.create.pt/?p=12852</guid>

					<description><![CDATA[<p>This post will explain how to provision a database programmatically in a Azure SQL database and add it to an Azure SQL failover group. Introduction An Azure SQL Server failover group is a group of databases that can be automatically or manually failed over from a primary server to a secondary server in a different [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/miguelisidoro/2024/01/24/provision-a-database-programmatically-in-azure-sql-database-with-a-failover-group/">Provision a database programmatically in Azure SQL database with a failover group</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This post will explain how to provision a database programmatically in a Azure SQL database and add it to an Azure SQL failover group.</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>An Azure SQL Server failover group is a group of databases that can be automatically or manually failed over from a primary server to a secondary server in a different Azure region in case of a disaster in the primary server. Failover groups provide high availability and disaster recovery for Azure SQL Server databases.</p>



<p>The process described in this post is composed by two main steps:</p>



<ul class="wp-block-list">
<li>Provisioning the database</li>



<li>Adding the database to the failover group </li>
</ul>



<h2 class="wp-block-heading">Provisioning the database</h2>



<p>The first step is to create the database. This step is composed by the following actions:</p>



<ul class="wp-block-list">
<li>Get the tenant information</li>



<li>Create the database</li>
</ul>



<p>Tenant information class:</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="791" height="381" src="https://blogit.create.pt/wp-content/uploads/2024/01/Regions.jpg" alt="" class="wp-image-12869" srcset="https://blogit.create.pt/wp-content/uploads/2024/01/Regions.jpg 791w, https://blogit.create.pt/wp-content/uploads/2024/01/Regions-300x145.jpg 300w, https://blogit.create.pt/wp-content/uploads/2024/01/Regions-768x370.jpg 768w, https://blogit.create.pt/wp-content/uploads/2024/01/Regions-696x335.jpg 696w" sizes="(max-width: 791px) 100vw, 791px" /></figure>



<p>Code to create database programatically:</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="722" src="https://blogit.create.pt/wp-content/uploads/2024/01/CreateDatabase-1024x722.jpg" alt="" class="wp-image-12866" srcset="https://blogit.create.pt/wp-content/uploads/2024/01/CreateDatabase-1024x722.jpg 1024w, https://blogit.create.pt/wp-content/uploads/2024/01/CreateDatabase-300x212.jpg 300w, https://blogit.create.pt/wp-content/uploads/2024/01/CreateDatabase-768x542.jpg 768w, https://blogit.create.pt/wp-content/uploads/2024/01/CreateDatabase-696x491.jpg 696w, https://blogit.create.pt/wp-content/uploads/2024/01/CreateDatabase-596x420.jpg 596w, https://blogit.create.pt/wp-content/uploads/2024/01/CreateDatabase-100x70.jpg 100w, https://blogit.create.pt/wp-content/uploads/2024/01/CreateDatabase.jpg 1065w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">Adding the database to the failover group</h2>



<p>The second step adds the newly created database to the failover group. This step is composed by the following actions:</p>



<ul class="wp-block-list">
<li>Get the failover group where we want to add the database</li>



<li>Re-add the existing databases to the failover group &#8211; necessary since when we get the failover group the list of databases of the group is empty and, without this step, the failover group would only have the new database</li>



<li>Add the new database to the failover group</li>
</ul>



<figure class="wp-block-image size-full"><img decoding="async" width="790" height="344" src="https://blogit.create.pt/wp-content/uploads/2024/01/Failovergroup.jpg" alt="" class="wp-image-12876" srcset="https://blogit.create.pt/wp-content/uploads/2024/01/Failovergroup.jpg 790w, https://blogit.create.pt/wp-content/uploads/2024/01/Failovergroup-300x131.jpg 300w, https://blogit.create.pt/wp-content/uploads/2024/01/Failovergroup-768x334.jpg 768w, https://blogit.create.pt/wp-content/uploads/2024/01/Failovergroup-696x303.jpg 696w" sizes="(max-width: 790px) 100vw, 790px" /></figure>



<h2 class="wp-block-heading">Other Articles</h2>



<p>To learn why your business should migrate to SharePoint Online and Office 365, click <a href="https://blogit.create.pt////miguelisidoro/2019/07/29/why-your-business-should-migrate-to-sharepoint-online-and-office-365-the-value-offer-part-1/" target="_blank" rel="noreferrer noopener">here</a> and <a href="https://blogit.create.pt////miguelisidoro/2019/07/29/why-your-business-should-migrate-to-sharepoint-online-and-office-365-the-value-offer-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p>If you want to learn how to develop SPFx solutions, click <a href="https://blogit.create.pt/miguelisidoro/2022/05/09/sharepoint-framework-spfx-learning-guide/" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p>If you want to learn how you can rename a modern SharePoint site, click <a href="https://blogit.create.pt////miguelisidoro/2019/09/23/how-to-rename-a-modern-sharepoint-site-url-in-office-365/" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p>If you want to learn how to save time time scheduling your meetings, click&nbsp;<a href="https://blogit.create.pt////miguelisidoro/2020/04/12/save-time-scheduling-microsoft-teams-meetings-using-findtime/" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p>If you want to learn how to enable Microsoft Teams Attendance List Download, click&nbsp;<a href="https://blogit.create.pt////miguelisidoro/2020/09/20/how-to-enable-teams-meeting-attendance-list-download-in-microsoft-365/" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p>If you want to learn how to create a dynamic org-wide team in Microsoft Teams with all active employees, click&nbsp;<a href="https://blogit.create.pt/miguelisidoro/2020/09/21/how-to-create-a-dynamic-team-in-microsoft-teams-with-all-active-employees-in-microsoft-365/" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p>If you want to modernize your SharePoint classic root site to a modern SharePoint site, click&nbsp;<a rel="noreferrer noopener" href="https://blogit.create.pt////miguelisidoro/2019/08/27/how-to-modernize-your-tenant-root-site-collection-in-office-365-using-invoke-spositeswap/" target="_blank">here</a>.</p>



<p>If you are a SharePoint administrator or a SharePoint developer who wants to learn more about how to install a SharePoint 2019 farm in an automated way using PowerShell, I invite you to click&nbsp;<a rel="noreferrer noopener" href="https://blogit.create.pt////miguelisidoro/2018/12/09/how-to-install-a-sharepoint-2019-farm-using-powershell-and-autospinstaller-part-1/" target="_blank">here</a>&nbsp;and&nbsp;<a rel="noreferrer noopener" href="https://blogit.create.pt////miguelisidoro/2018/12/09/how-to-install-a-sharepoint-2019-farm-using-powershell-and-autospinstaller-part-2/" target="_blank">here</a>.</p>



<p>If you learn how to greatly speed up your SharePoint farm update process to ensure your SharePoint farm keeps updated and you stay one step closer to start your move to the cloud, click&nbsp;<a rel="noreferrer noopener" href="https://blogit.create.pt////miguelisidoro/2019/05/02/how-to-speed-up-the-installation-of-sharepoint-cumulative-updates-using-powershell-step-by-step/" target="_blank">here</a>.</p>



<p>If you prefer to use the traditional method to update your farm and want to learn all the steps and precautions necessary to successfully keep your SharePoint farm updated, click&nbsp;<a rel="noreferrer noopener" href="https://blogit.create.pt////miguelisidoro/2019/04/08/how-to-install-sharepoint-cumulative-updates-in-a-sharepoint-farm-step-by-step/" target="_blank">here</a>.</p>



<p>If you want to learn how to upgrade a SharePoint 2013 farm to SharePoint 2019, click&nbsp;<a rel="noreferrer noopener" href="https://blogit.create.pt////miguelisidoro/2019/03/06/how-to-upgrade-from-sharepoint-2013-to-sharepoint-2019-step-by-step-part-1/" target="_blank">here&nbsp;</a>and&nbsp;<a rel="noreferrer noopener" href="https://blogit.create.pt////miguelisidoro/2019/03/06/how-to-upgrade-from-sharepoint-2013-to-sharepoint-2019-step-by-step-part-2/" target="_blank">here</a>.</p>



<p>If SharePoint 2019 is still not an option, you can learn more about how to install a SharePoint 2016 farm in an automated way using PowerShell, click&nbsp;<a rel="noreferrer noopener" href="https://blogit.create.pt////miguelisidoro/2018/07/28/how-to-install-a-sharepoint-2016-farm-using-powershell-and-autospinstaller-part-1/" target="_blank">here</a>&nbsp;and&nbsp;<a rel="noreferrer noopener" href="https://blogit.create.pt////miguelisidoro/2018/07/28/how-to-install-a-sharepoint-2016-farm-using-powershell-and-autospinstaller-part-2/" target="_blank">here</a>.</p>



<p>If you want to learn how to upgrade a SharePoint 2010 farm to SharePoint 2016, click&nbsp;<a rel="noreferrer noopener" href="https://blogit.create.pt////miguelisidoro/2019/02/04/sharepoint-upgrade-upgrading-a-sharepoint-2010-farm-to-sharepoint-2016-step-by-step-part-1/" target="_blank">here&nbsp;</a>and&nbsp;<a rel="noreferrer noopener" href="https://blogit.create.pt////miguelisidoro/2019/02/04/sharepoint-upgrade-upgrading-a-sharepoint-2010-farm-to-sharepoint-2016-step-by-step-part-2/" target="_blank">here</a>.</p>



<p>If you are new to SharePoint and Office 365 and want to learn all about it, take a look at these&nbsp;<a rel="noreferrer noopener" href="https://blogit.create.pt////miguelisidoro/2018/10/17/sharepoint-and-office-365-learning-resources/" target="_blank">learning resources</a>.</p>



<p>If you are work in a large organization who is using Office 365 or thinking to move to Office 365 and is considering between a single or multiple Office 365 tenants, I invite you to read&nbsp;<a rel="noreferrer noopener" href="https://blogit.create.pt////miguelisidoro/2019/01/07/pros-and-cons-of-single-tenant-vs-multiple-tenants-in-office-365/" target="_blank">this article</a>.</p>



<p>If you want to know all about the latest SharePoint and Office 365 announcements from Ignite and some more recent announcements, including Microsoft Search, What’s New to Build a Modern Intranet with SharePoint in Office 365, Deeper Integration between Microsoft Teams and SharePoint and the latest news on SharePoint development, click&nbsp;<a rel="noreferrer noopener" href="https://blogit.create.pt////miguelisidoro/2018/11/21/whats-new-for-sharepoint-and-office-365-after-microsoft-ignite-2018/" target="_blank">here</a>.</p>



<p>If your organization is still not ready to go all in to SharePoint Online and Office 365, a hybrid scenario may be the best choice. SharePoint 2019 RTM was recently announced and if you to learn all about SharePoint 2019 and all its features, click <a href="https://blogit.create.pt////miguelisidoro/2018/11/01/meet-the-new-modern-sharepoint-server-sharepoint-2019-rtm-is-here/" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p>Happy Coding!</p>
<p>The post <a href="https://blogit.create.pt/miguelisidoro/2024/01/24/provision-a-database-programmatically-in-azure-sql-database-with-a-failover-group/">Provision a database programmatically in Azure SQL database with a failover group</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/miguelisidoro/2024/01/24/provision-a-database-programmatically-in-azure-sql-database-with-a-failover-group/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>TWIL: The weird way .NET&#8217;s config system parses JSONs</title>
		<link>https://blogit.create.pt/hugobarroca/2022/02/07/twil-the-weird-way-nets-config-system-parses-jsons/</link>
					<comments>https://blogit.create.pt/hugobarroca/2022/02/07/twil-the-weird-way-nets-config-system-parses-jsons/#respond</comments>
		
		<dc:creator><![CDATA[Hugo Barroca]]></dc:creator>
		<pubDate>Mon, 07 Feb 2022 13:01:05 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[appsettings]]></category>
		<guid isPermaLink="false">https://blogit.create.pt/?p=12619</guid>

					<description><![CDATA[<p>The day is a Friday. We were calmly deploying an app we tested locally to the test environment. The error we had was pointing towards the config files. Off we go to check the appsettings.json file… Every value seems correct, but the error is definitely pointing us here. Here&#8217;s a simplified version of the offending [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/hugobarroca/2022/02/07/twil-the-weird-way-nets-config-system-parses-jsons/">TWIL: The weird way .NET&#8217;s config system parses JSONs</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>The day is a Friday. We were calmly deploying an app we tested locally to the test environment. The error we had was pointing towards the config files. Off we go to check the appsettings.json file…</p>



<p>Every value seems correct, but the error is definitely pointing us here. Here&#8217;s a simplified version of the offending line:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
Console.Writeline(AConfig.ASubConfig);
</pre></div>


<p>And the corresponding appsettings:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
{
    &quot;AConfig&quot; : {
        &quot;ASubConfig&quot; : &#x5B;]
    }
}
</pre></div>


<p>&#8220;But an empty array is not the same as a null value! And even if it was, it&#8217;s a value inside the &#8220;ASubConfig&#8221; property! There&#8217;s no way for this to be null!&#8221; was what I thought. And I thought wrong.</p>



<h2 class="wp-block-heading" id="how-the-file-is-actually-parsed">How the file is actually parsed</h2>



<p>Actually, there&#8217;s a way for it to be null. Or at least, the JSON Provider which is gonna look at ours JSONs thinks so. Since .NET&#8217;s config system is ready to take in different providers, it was built with the common points of said providers in mind… And hierarchies aren&#8217;t one of those points.</p>



<p>What happens is that the JSON Provider&#8217;s parser is going to look at our JSON file and it&#8217;s going to map all those informations to a dictionary, in which every value is mapped with a key which corresponds to the path to that value in the file.</p>



<p>The &#8220;gotcha&#8221; here is in the way the arrays are processed: Each index of each array is processed as a part of the path. Meaning, that the following appsettings:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
{
    &quot;AnArray&quot; : &#x5B;&quot;AThing&quot;, &quot;AnotherThing&quot;, &quot;AThirdThing&quot;]
}
</pre></div>


<p>Will originate a dictionary with the following entries:</p>



<ul class="wp-block-list"><li>AnArray:0 = &#8220;AThing&#8221;</li><li>AnArray:1 = &#8220;AnotherThing&#8221;</li><li>AnArray:2 = &#8220;AThirdThing&#8221;</li></ul>



<h2 class="wp-block-heading" id="why-do-empty-arrays-cause-an-issue">Why do empty arrays cause an issue?</h2>



<p>What happens if the array is empty? Well, by convention, an empty array wont originate any entries in our dictionary… So, to the .NET binder which is gonna look at our dictionary, that array doesn&#8217;t exist at all.</p>



<p>Even moreso, as there is no value inside that array which we can map to some path, every object on top of it in the hierarchy won&#8217;t have any value we can map either, meaning those objects won&#8217;t exist themselves (assuming they don&#8217;t have any other properties with not null values).</p>



<p>In practice, our dictionary will be empty, our .NET binder won&#8217;t be able to map anything, and the number of &#8220;WTH&#8221;s per second will spike before lunch time.</p>



<p>TLDR: .NET&#8217;s config system treats any object in appsettings.json that does not have any value associated with it&#8217;s properties as if it didn&#8217;t exist, and the same happens if that value is an empty array.</p>



<p>If anyone wants to read more on this, here&#8217;s a link for the github issue where I found most of this information:</p>



<p><a href="https://github.com/dotnet/extensions/issues/1341">https://github.com/dotnet/extensions/issues/1341</a></p>



<p>Happy coding everyone!</p>
<p>The post <a href="https://blogit.create.pt/hugobarroca/2022/02/07/twil-the-weird-way-nets-config-system-parses-jsons/">TWIL: The weird way .NET&#8217;s config system parses JSONs</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/hugobarroca/2022/02/07/twil-the-weird-way-nets-config-system-parses-jsons/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>log4net PatternLayout and PatternConverter</title>
		<link>https://blogit.create.pt/ricardocosta/2016/07/11/log4net-patternlayout-and-patternconverter/</link>
					<comments>https://blogit.create.pt/ricardocosta/2016/07/11/log4net-patternlayout-and-patternconverter/#respond</comments>
		
		<dc:creator><![CDATA[Ricardo Costa]]></dc:creator>
		<pubDate>Mon, 11 Jul 2016 16:50:58 +0000</pubDate>
				<category><![CDATA[log4net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[.NET]]></category>
		<guid isPermaLink="false">http://blogit.create.pt/ricardocosta/?p=1221</guid>

					<description><![CDATA[<p>I have the following scenario: I&#8217;m using Unity dependency injection container and interception techniques to log some WCF operation calls. I need to log the input parameters and also the result of these operations so I&#8217;ve implemented a CallHandler that I can apply to whatever methods that I need to intercept. In this CallHandler I&#8217;ve [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/ricardocosta/2016/07/11/log4net-patternlayout-and-patternconverter/">log4net PatternLayout and PatternConverter</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I have the following scenario:</p>
<p>I&#8217;m using <a href="https://github.com/unitycontainer/unity" target="_blank">Unity</a> dependency injection container and <a href="https://msdn.microsoft.com/en-us/library/dn178466(v=pandp.30).aspx" target="_blank">interception</a> techniques to log some WCF operation calls. I need to log the input parameters and also the result of these operations so I&#8217;ve implemented a <a href="https://msdn.microsoft.com/en-us/library/ff660871(v=pandp.20).aspx" target="_blank">CallHandler</a> that I can apply to whatever methods that I need to intercept.</p>
<p>In this CallHandler I&#8217;ve defined a class called LogEntry and I&#8217;m logging with log4net. Something like this:</p>
<pre class="brush: csharp; title: ; notranslate">

LogEntry logEntry = new LogEntry();
....
// set some base properties
logEntry.MethodName = input.MethodBase.Name;
logEntry.TypeName = input.Target.GetType().FullName;
...
// set input parameters
logEntry.Input = ....;
...
// set return value
logEntry.ReturnValue = result.ReturnValue;
.....
// set total method duration
logEntry.CallTime = stopwatch.Elapsed.TotalMilliseconds;
.....

// use log4net logger to log this information
logger.Debug(logEntry);
</pre>
<p>So this LogEntry class has some properties that will hold the information that I want to log. Now I need to capture these properties and configure the log4net <a href="https://logging.apache.org/log4net/release/config-examples.html" target="_blank">appenders</a> properly.</p>
<p>I&#8217;m using log4net PatternLayout and PatternConverter features. Let&#8217;s start with PatternLayout</p>
<pre class="brush: csharp; title: ; notranslate">

///&lt;summary&gt;
/// Extended version of &lt;see cref=&quot;PatternLayout&quot;/&gt;
/// &lt;/summary&gt;


public class ExtendedPatternLayout : PatternLayout
{
 ///&lt;summary&gt;
 /// Initializes a new instance of the &lt;see cref=&quot;ExtendedPatternLayout&quot;/&gt; class.
 /// &lt;/summary&gt;;


 public ExtendedPatternLayout()
 {
   this.AddConverter(new ConverterInfo()
   {
     Name = &quot;logEntry&quot;,
     Type = typeof(LogEntryConverter),
   });
 }
}

</pre>
<p>This layout just adds a new Converter named &#8220;logEntry&#8221; implemented by the class LogEntryConverter. There is no reference to LogEntry class here. And the LogEntryConverter class is here:</p>
<pre class="brush: csharp; title: ; notranslate">

 /// &lt;summary&gt;
 /// Custom &lt;see cref=&quot;PatternConverter&quot;/&gt; to handle &lt;see cref=&quot;LogEntry&quot;/&gt;
 /// &lt;/summary&gt;
 public class LogEntryConverter : PatternConverter
 {
   /// &lt;summary&gt;
   /// Converts the specified writer.
   /// &lt;/summary&gt;
   /// &lt;param name=&quot;writer&quot;&gt;The writer.&lt;/param&gt;
   /// &lt;param name=&quot;state&quot;&gt;The state.&lt;/param&gt;
   protected override void Convert(System.IO.TextWriter writer, object state)
   {
       var loggingEvent = state as LoggingEvent;
       var logEntry = loggingEvent.MessageObject as LogEntry;

       if (logEntry != null)
       {
          switch (this.Option.ToLower())
          {
             case &quot;calltime&quot;:
               writer.Write(logEntry.CallTime.HasValue ? logEntry.CallTime.Value : 0);
               break;
             case &quot;methodname&quot;:
               writer.Write(logEntry.MethodName);
               break;
             case &quot;returnvalue&quot;:
               writer.Write(SerializationService.SerializeToJSON(logEntry.ReturnValue));
               break;
             ..........
             ..........
             default:
               writer.Write(string.Empty);
               break;
          }
       }
    }
 }

</pre>
<p>I&#8217;ve made the code smaller but you need to check for null references!</p>
<p>I&#8217;m using a JSON serialization technique to grab the representation of the method&#8217;s return value.</p>
<p>I need to override the Convert method and access state object that is a log4net <a href="https://logging.apache.org/log4net/log4net-1.2.13/release/sdk/log4net.Core.LoggingEvent.html" target="_blank">LoggingEvent</a> object. This object has my logged object from the CallHandler which is a LogEntry object. Based on the <a href="https://logging.apache.org/log4net/release/sdk/index.html" target="_blank">Option</a> property of the converter I can choose which property to write.</p>
<p>And finally I can configure my log4net like this</p>
<pre class="brush: xml; title: ; notranslate">

&lt;layout type=&quot;ExtendedPatternLayout&quot;&gt;
  &lt;conversionPattern value=&quot;%logEntry{CallTime}&quot; /&gt;
&lt;/layout&gt;

</pre>
<p>You can see the conversionPattern follows this syntax: %convertername{option}</p>
<p>The post <a href="https://blogit.create.pt/ricardocosta/2016/07/11/log4net-patternlayout-and-patternconverter/">log4net PatternLayout and PatternConverter</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/ricardocosta/2016/07/11/log4net-patternlayout-and-patternconverter/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Custom properties log4net</title>
		<link>https://blogit.create.pt/ricardocosta/2015/11/23/custom-properties-log4net/</link>
					<comments>https://blogit.create.pt/ricardocosta/2015/11/23/custom-properties-log4net/#respond</comments>
		
		<dc:creator><![CDATA[Ricardo Costa]]></dc:creator>
		<pubDate>Mon, 23 Nov 2015 10:20:21 +0000</pubDate>
				<category><![CDATA[log4net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[.NET]]></category>
		<guid isPermaLink="false">http://blogit.create.pt/ricardocosta/?p=991</guid>

					<description><![CDATA[<p>I had the need to add some custom properties in my log4net messages. I used the log4net contexts like this: log4net.ThreadContext.Properties&#x5B;MessageIdKey] = messageId; And then updated my rolling file appender: &#60;!-- Rolling File Appender --&#62; &#60;appender name=&#34;RollingFileAppender&#34; type=&#34;log4net.Appender.RollingFileAppender&#34;&#62; &#60;file value=&#34;log.txt&#34; /&#62; &#60;appendToFile value=&#34;true&#34; /&#62; &#60;rollingStyle value=&#34;Size&#34; /&#62; &#60;maxSizeRollBackups value=&#34;5&#34; /&#62; &#60;maximumFileSize value=&#34;10MB&#34; /&#62; &#60;staticLogFileName value=&#34;true&#34; [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/ricardocosta/2015/11/23/custom-properties-log4net/">Custom properties log4net</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I had the need to add some custom properties in my <a title="log4net" href="https://logging.apache.org/log4net/" target="_blank">log4net</a> messages.</p>
<p>I used the <a title="log4net contexts" href="https://logging.apache.org/log4net/release/manual/contexts.html" target="_blank">log4net contexts</a> like this:</p>
<pre class="brush: csharp; title: ; notranslate">

log4net.ThreadContext.Properties&#x5B;MessageIdKey] = messageId;

</pre>
<p>And then updated my rolling file appender:</p>
<pre class="brush: xml; title: ; notranslate">

&lt;!-- Rolling File Appender --&gt;
&lt;appender name=&quot;RollingFileAppender&quot; type=&quot;log4net.Appender.RollingFileAppender&quot;&gt;
&lt;file value=&quot;log.txt&quot; /&gt;
&lt;appendToFile value=&quot;true&quot; /&gt;
&lt;rollingStyle value=&quot;Size&quot; /&gt;
&lt;maxSizeRollBackups value=&quot;5&quot; /&gt;
&lt;maximumFileSize value=&quot;10MB&quot; /&gt;
&lt;staticLogFileName value=&quot;true&quot; /&gt;
&lt;layout type=&quot;log4net.Layout.PatternLayout&quot;&gt;
&lt;conversionPattern value=&quot;%date{dd-MM-yyyy HH:mm:ss,fff} (%logger) &#x5B;%2thread]     &#x5B;%property{MessageId}] %5level %message%newline&quot; /&gt;
&lt;/layout&gt;
&lt;/appender&gt;

</pre>
<p>and my AdoNetAppender:</p>
<pre class="brush: xml; title: ; notranslate">

&lt;!-- ADO Appender --&gt;
 &lt;appender name=&quot;AdoNetAppender&quot; type=&quot;log4net.Appender.AdoNetAppender&quot;&gt;
 &lt;bufferSize value=&quot;5&quot; /&gt;
 &lt;lossy value=&quot;false&quot; /&gt;
 &lt;connectionType value=&quot;System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&quot; /&gt;
 &lt;connectionString value=&quot;data source=localhost;initial catalog=MyDb;integrated security=true;&quot; /&gt;
 &lt;commandText value=&quot;INSERT INTO Log (&#x5B;Date],&#x5B;Thread],&#x5B;Level],&#x5B;Logger],&#x5B;Message],&#x5B;Exception],&#x5B;MessageId]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception, @messageId)&quot; /&gt;

 ......

 &lt;parameterName value=&quot;@messageId&quot; /&gt;
 &lt;dbType value=&quot;String&quot; /&gt;
 &lt;size value=&quot;255&quot; /&gt;
 &lt;layout type=&quot;log4net.Layout.PatternLayout&quot;&gt;
 &lt;conversionPattern value=&quot;%property{MessageId}&quot; /&gt;
 &lt;/layout&gt;
 &lt;/parameter&gt;

 &lt;/appender&gt;

</pre>
<p>The post <a href="https://blogit.create.pt/ricardocosta/2015/11/23/custom-properties-log4net/">Custom properties log4net</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/ricardocosta/2015/11/23/custom-properties-log4net/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
