<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ask Gemini</title>
    <description>The latest articles on DEV Community by Ask Gemini (@ask_gemini).</description>
    <link>https://dev.to/ask_gemini</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3632918%2F1da453fb-3922-42fc-9867-df786a0f66fc.png</url>
      <title>DEV Community: Ask Gemini</title>
      <link>https://dev.to/ask_gemini</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ask_gemini"/>
    <language>en</language>
    <item>
      <title>NLog vs Serilog in .NET — Which Logging Framework Should You Use in 2026?</title>
      <dc:creator>Ask Gemini</dc:creator>
      <pubDate>Sat, 18 Apr 2026 15:08:45 +0000</pubDate>
      <link>https://dev.to/ask_gemini/nlog-vs-serilog-in-net-which-logging-framework-should-you-use-in-2026-262f</link>
      <guid>https://dev.to/ask_gemini/nlog-vs-serilog-in-net-which-logging-framework-should-you-use-in-2026-262f</guid>
      <description>&lt;h1&gt;
  
  
  NLog vs Serilog in .NET: A Real-World Comparison Guide
&lt;/h1&gt;

&lt;p&gt;Choosing the right logging framework in .NET is a critical decision for building production-ready applications. This guide explains not just the differences between NLog and Serilog, but also when and why to use each in real-world scenarios.&lt;/p&gt;

&lt;p&gt;Before going through the content, just go through our application &lt;a href="https://theigknight.com" rel="noopener noreferrer"&gt;The IgKnight&lt;/a&gt; for exploring different techs&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Why Logging Matters in Modern .NET Applications
&lt;/h2&gt;

&lt;p&gt;Logging is not just for debugging—it is essential for understanding how your application behaves in production.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Logging is Important
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Helps debug issues in production
&lt;/li&gt;
&lt;li&gt;Tracks application behavior and user activity
&lt;/li&gt;
&lt;li&gt;Monitors performance and failures
&lt;/li&gt;
&lt;li&gt;Enables observability in distributed systems
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In modern architectures (especially cloud and container-based systems), logging is a core requirement.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Understanding NLog
&lt;/h2&gt;

&lt;p&gt;NLog is a mature and widely used logging framework in the .NET ecosystem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Simple configuration (XML or code-based)
&lt;/li&gt;
&lt;li&gt;High performance
&lt;/li&gt;
&lt;li&gt;Supports multiple targets (file, database, console)
&lt;/li&gt;
&lt;li&gt;Stable and battle-tested
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;Logger&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;LogManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetCurrentClassLogger&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Application started"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Something went wrong"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  When to Use NLog
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;When you need a simple logging setup
&lt;/li&gt;
&lt;li&gt;When working with legacy systems
&lt;/li&gt;
&lt;li&gt;When structured logging is not required
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Understanding Serilog
&lt;/h2&gt;

&lt;p&gt;Serilog is a modern logging framework designed for structured logging.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Structured logging (JSON-based logs)
&lt;/li&gt;
&lt;li&gt;Powerful integrations with modern tools
&lt;/li&gt;
&lt;li&gt;Clean and flexible configuration
&lt;/li&gt;
&lt;li&gt;Ideal for cloud-native applications
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Logger&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;LoggerConfiguration&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WriteTo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateLogger&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Information&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Application started"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  When to Use Serilog
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;When you need structured logging
&lt;/li&gt;
&lt;li&gt;When building scalable or cloud-based systems
&lt;/li&gt;
&lt;li&gt;When log analysis and filtering are important
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. NLog vs Serilog — Key Differences
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;NLog&lt;/th&gt;
&lt;th&gt;Serilog&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Ease of Setup&lt;/td&gt;
&lt;td&gt;Very simple&lt;/td&gt;
&lt;td&gt;Slightly structured&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Structured Logging&lt;/td&gt;
&lt;td&gt;Limited&lt;/td&gt;
&lt;td&gt;Excellent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;Good&lt;/td&gt;
&lt;td&gt;Very good&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ecosystem&lt;/td&gt;
&lt;td&gt;Mature&lt;/td&gt;
&lt;td&gt;Modern &amp;amp; growing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cloud Integration&lt;/td&gt;
&lt;td&gt;Basic&lt;/td&gt;
&lt;td&gt;Strong&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  5. Real-World Perspective
&lt;/h2&gt;

&lt;p&gt;In real-world applications, the choice of logging framework depends on system requirements.&lt;/p&gt;

&lt;p&gt;While building a platform that executes user-submitted code inside Docker containers, logging became a critical component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Requirements in Production Systems
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Track logs per user execution
&lt;/li&gt;
&lt;li&gt;Debug failed code runs
&lt;/li&gt;
&lt;li&gt;Monitor system performance
&lt;/li&gt;
&lt;li&gt;Handle high-volume logs efficiently
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Observations
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;NLog works well for simple and traditional logging needs
&lt;/li&gt;
&lt;li&gt;Serilog excels in structured logging and modern architectures
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  6. Logging in Real Applications (IgKnight Example)
&lt;/h2&gt;

&lt;p&gt;In platforms like IgKnight, where users execute code in an online compiler, logging plays a vital role.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use Cases
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Capturing execution logs per user
&lt;/li&gt;
&lt;li&gt;Tracking errors during code execution
&lt;/li&gt;
&lt;li&gt;Monitoring system performance
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Structured logging helps in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Filtering logs efficiently
&lt;/li&gt;
&lt;li&gt;Analyzing system behavior
&lt;/li&gt;
&lt;li&gt;Debugging faster in production
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are building similar systems, choosing the right logging framework is crucial.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. Final Verdict
&lt;/h2&gt;

&lt;p&gt;Both frameworks are powerful, but the choice depends on your needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Choose NLog if:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You prefer simplicity
&lt;/li&gt;
&lt;li&gt;You are working on traditional systems
&lt;/li&gt;
&lt;li&gt;You do not need structured logs
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Choose Serilog if:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You need structured logging
&lt;/li&gt;
&lt;li&gt;You are building modern applications
&lt;/li&gt;
&lt;li&gt;You are working with cloud or container-based systems
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 For most modern .NET applications, &lt;strong&gt;Serilog is the recommended choice&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. What’s Next?
&lt;/h2&gt;

&lt;p&gt;Logging is just one part of building reliable systems.&lt;/p&gt;

&lt;p&gt;To build production-ready applications, also focus on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unit testing
&lt;/li&gt;
&lt;li&gt;Error handling
&lt;/li&gt;
&lt;li&gt;Monitoring and observability
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Learn more:&lt;br&gt;&lt;br&gt;
&lt;a href="https://theigknight.com/documentation/dotnet/dotnet-logging" rel="noopener noreferrer"&gt;Mastering .NET Logging and Observability&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  8. Additional Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://theigknight.com/documentation/dotnet/dotnet-introduction" rel="noopener noreferrer"&gt;.NET Introduction&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://theigknight.com/documentation/csharp/csharp-introduction" rel="noopener noreferrer"&gt;C# Documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://theigknight.com/documentation/java/java-introduction" rel="noopener noreferrer"&gt;Java Documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://theigknight.com/documentation/python/python-introduction" rel="noopener noreferrer"&gt;Python Documentation&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Choosing between NLog and Serilog is not about which is better—it’s about what fits your system.&lt;/p&gt;

&lt;p&gt;By understanding:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your application requirements
&lt;/li&gt;
&lt;li&gt;Your logging needs
&lt;/li&gt;
&lt;li&gt;Your system architecture
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;you can make the right decision and build more reliable, maintainable applications.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>csharp</category>
      <category>dotnet</category>
      <category>monitoring</category>
    </item>
    <item>
      <title>Unit Testing in .NET: A Comprehensive Guide</title>
      <dc:creator>Ask Gemini</dc:creator>
      <pubDate>Mon, 30 Mar 2026 16:48:51 +0000</pubDate>
      <link>https://dev.to/ask_gemini/unit-testing-in-net-a-comprehensive-guide-ib3</link>
      <guid>https://dev.to/ask_gemini/unit-testing-in-net-a-comprehensive-guide-ib3</guid>
      <description>&lt;h1&gt;
  
  
  Unit Testing in .NET: A Comprehensive Guide
&lt;/h1&gt;

&lt;p&gt;To ensure a high-quality, production-ready application, unit testing must be treated as a core part of development—not an afterthought. This guide explains not only how to write tests in .NET using xUnit, but also why each concept matters.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Fundamentals of Unit Testing
&lt;/h2&gt;

&lt;p&gt;Unit testing is the practice of verifying the smallest pieces of code (typically methods) in isolation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Unit Testing Matters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ensures correctness of business logic
&lt;/li&gt;
&lt;li&gt;Prevents regressions during future changes
&lt;/li&gt;
&lt;li&gt;Improves developer confidence
&lt;/li&gt;
&lt;li&gt;Enables faster refactoring
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the .NET ecosystem, common testing frameworks include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;xUnit (modern, fast, recommended)
&lt;/li&gt;
&lt;li&gt;NUnit
&lt;/li&gt;
&lt;li&gt;MSTest
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This guide focuses on xUnit due to its simplicity and performance.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. The AAA Pattern (Arrange, Act, Assert)
&lt;/h2&gt;

&lt;p&gt;A well-structured test follows the AAA pattern.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Use AAA?
&lt;/h3&gt;

&lt;p&gt;It enforces clarity and consistency, making tests easy to read and maintain.&lt;/p&gt;

&lt;h3&gt;
  
  
  Structure
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Arrange&lt;/strong&gt;: Prepare required objects and data
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Act&lt;/strong&gt;: Execute the method under test
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assert&lt;/strong&gt;: Validate the result
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;CalculateTax_ShouldReturnTwentyPercent_WhenIncomeIsHigh&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Arrange&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;calculator&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;TaxCalculator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;income&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;100000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Act&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Calculate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;income&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Assert&lt;/span&gt;
    &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;20000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;p&gt;This test verifies that the tax calculation logic returns 20% for a high income. The method is tested independently without external dependencies.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Fact vs Theory in xUnit
&lt;/h2&gt;

&lt;p&gt;xUnit provides two ways to define tests depending on the use case.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fact
&lt;/h3&gt;

&lt;p&gt;Used when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The test has fixed input
&lt;/li&gt;
&lt;li&gt;Only one scenario needs validation
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;IsAdult_ShouldReturnTrue_WhenAgeIsAbove18&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;User&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsAdult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;25&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;True&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Theory
&lt;/h3&gt;

&lt;p&gt;Used when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiple input combinations must be tested
&lt;/li&gt;
&lt;li&gt;You want to avoid duplicate test methods
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Theory&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;InlineData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;InlineData&lt;/span&gt;&lt;span class="p"&gt;(-&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;InlineData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Add_ShouldReturnCorrectSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SimpleMath&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why It Matters
&lt;/h3&gt;

&lt;p&gt;Using Theory improves test coverage while keeping your test suite concise and maintainable.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Isolation and Mocking
&lt;/h2&gt;

&lt;p&gt;Real-world applications depend on external systems like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Databases
&lt;/li&gt;
&lt;li&gt;APIs
&lt;/li&gt;
&lt;li&gt;Email services
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Problem
&lt;/h3&gt;

&lt;p&gt;Directly using these dependencies in tests leads to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Slow execution
&lt;/li&gt;
&lt;li&gt;Flaky tests
&lt;/li&gt;
&lt;li&gt;Hard-to-maintain code
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Solution: Mocking
&lt;/h3&gt;

&lt;p&gt;Mocking replaces real dependencies with controlled fake implementations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using Moq
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;mockService&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Mock&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IEmailService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;

&lt;span class="n"&gt;mockService&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;service&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;It&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IsAny&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;()))&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Returns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;controller&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;UserController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mockService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A fake email service is created
&lt;/li&gt;
&lt;li&gt;Behavior is predefined
&lt;/li&gt;
&lt;li&gt;No real email is sent during testing
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Benefits
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Faster tests
&lt;/li&gt;
&lt;li&gt;Reliable results
&lt;/li&gt;
&lt;li&gt;True isolation of business logic
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5. Running Tests in Docker
&lt;/h2&gt;

&lt;p&gt;Modern applications should run tests in containerized environments.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ensures environment consistency
&lt;/li&gt;
&lt;li&gt;Prevents “works on my machine” issues
&lt;/li&gt;
&lt;li&gt;Integrates easily with CI/CD pipelines
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;mcr.microsoft.com/dotnet/sdk:8.0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;build&lt;/span&gt;

&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /src&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;dotnet &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="s2"&gt;"MyProject.Tests.csproj"&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; Release
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Key Idea
&lt;/h3&gt;

&lt;p&gt;The build fails if tests fail, preventing broken code from being deployed.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Advanced Observability: What’s Next?
&lt;/h2&gt;

&lt;p&gt;Testing ensures correctness before deployment, but production systems require monitoring.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Observability Matters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Detect runtime errors
&lt;/li&gt;
&lt;li&gt;Monitor performance
&lt;/li&gt;
&lt;li&gt;Track system behavior
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Learn more:&lt;br&gt;&lt;br&gt;
&lt;a href="https://theigknight.com/documentation/dotnet/dotnet-logging" rel="noopener noreferrer"&gt;Mastering .NET Logging and Observability&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  7. Additional Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://theigknight.com/documentation/dotnet/dotnet-introduction" rel="noopener noreferrer"&gt;.NET Introduction&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://theigknight.com/documentation/csharp/csharp-introduction" rel="noopener noreferrer"&gt;C# Documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://theigknight.com/documentation/java/java-introduction" rel="noopener noreferrer"&gt;Java Documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://theigknight.com/documentation/python/python-introduction" rel="noopener noreferrer"&gt;Python Documentation&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Unit testing is not optional in modern development—it is essential.&lt;/p&gt;

&lt;p&gt;By understanding:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why tests are written
&lt;/li&gt;
&lt;li&gt;How to structure them properly
&lt;/li&gt;
&lt;li&gt;How to isolate dependencies
&lt;/li&gt;
&lt;li&gt;How to integrate them into your pipeline
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;you build systems that are reliable, maintainable, and production-ready.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>ai</category>
      <category>tutorial</category>
      <category>learning</category>
    </item>
    <item>
      <title>How to Build a Secure Multi-Language Online Compiler Using Angular + .NET Core + Docker</title>
      <dc:creator>Ask Gemini</dc:creator>
      <pubDate>Thu, 27 Nov 2025 14:33:36 +0000</pubDate>
      <link>https://dev.to/ask_gemini/how-to-build-a-secure-multi-language-online-compiler-using-angular-net-core-docker-3k10</link>
      <guid>https://dev.to/ask_gemini/how-to-build-a-secure-multi-language-online-compiler-using-angular-net-core-docker-3k10</guid>
      <description>&lt;p&gt;Online compilers are no longer just a learning tool — they are powering coding interviews, developer onboarding, and cloud-based IDEs. If you want to build one that supports multiple languages like &lt;a href="https://theigknight.com/documentation/python/python-introduction" rel="noopener noreferrer"&gt;&lt;b&gt;&lt;/b&gt;&lt;/a&gt;, C, &lt;a href="https://theigknight.com/documentation/java/java-introduction" rel="noopener noreferrer"&gt;Java&lt;/a&gt; and  &lt;a href="https://theigknight.com/documentation/csharp/csharp-introduction" rel="noopener noreferrer"&gt;C#&lt;/a&gt;, you need to think about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Developer experience (the coding feel)&lt;/li&gt;
&lt;li&gt;Execution safety&lt;/li&gt;
&lt;li&gt;Performance &amp;amp; scalability
In this guide, I’ll show how we built Igknight, a modern multi-language online compiler, using:
&lt;strong&gt;Angular + Monaco Editor + .NET Core + Docker Sandbox Execution&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frontend: Angular + Monaco = VS Code in the Browser
&lt;/h2&gt;

&lt;p&gt;For enterprise-quality development, Angular gives consistency and long-term maintainability.&lt;/p&gt;

&lt;p&gt;To create a real coding environment, we integrate Monaco (the engine behind VS Code):&lt;br&gt;
✔ Syntax highlighting for dozens of languages&lt;br&gt;
✔ Auto-complete + IntelliSense-like suggestions&lt;br&gt;
✔ Keyboard shortcuts devs already know&lt;br&gt;
✔ Themeing + fully customizable UI&lt;br&gt;
We also apply custom CSS to match Igknight platform styling so users feel like they're inside a real IDE. If you want to explore the underlying frontend technologies, you can learn more about styling with &lt;a href="https://theigknight.com/documentation/css/css-introduction" rel="noopener noreferrer"&gt;CSS&lt;/a&gt; and building scalable frontends with &lt;a href="https://theigknight.com/documentation/ts/ts-introduction" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt;. We also ensure valid HTML structure for the editor components.&lt;br&gt;
🛡 &lt;strong&gt;Client-Side Code Validation&lt;/strong&gt;&lt;br&gt;
Before sending to the server, we check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Language selection vs code format&lt;/li&gt;
&lt;li&gt;Code length limits&lt;/li&gt;
&lt;li&gt;Basic malicious pattern filtering&lt;/li&gt;
&lt;li&gt;Required structure (e.g., main() for Java/C)
This saves backend resources and improves speed&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Backend: .NET Core Handles Execution Logic
&lt;/h2&gt;

&lt;p&gt;The backend uses .NET Core to serve the API and manage the secure execution workflow. The &lt;a href="https://theigknight.com/documentation/dotnet/dotnet-introduction" rel="noopener noreferrer"&gt;.NET platform&lt;/a&gt; is an excellent choice for its high performance and robust security features, which are critical for this task.&lt;br&gt;
The backend is responsible for:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Receiving code + selected language&lt;/li&gt;
&lt;li&gt;Creating a temporary file securely&lt;/li&gt;
&lt;li&gt;Selecting the correct Docker runner image&lt;/li&gt;
&lt;li&gt;Executing with:&lt;/li&gt;
&lt;li&gt;CPU + memory usage limits&lt;/li&gt;
&lt;li&gt;No network access&lt;/li&gt;
&lt;li&gt; Execution timeout&lt;/li&gt;
&lt;li&gt;Capturing output + errors&lt;/li&gt;
&lt;li&gt;Destroying container → no persistent files
&lt;strong&gt;Multi-Language Support with Docker&lt;/strong&gt;
We build lightweight, language-specific Docker images. This container-per-execution model is the key to both security and multi-language support.
Language,Execution Strategy &lt;a href="https://theigknight.com/documentation/python/python-introduction" rel="noopener noreferrer"&gt;Python&lt;/a&gt;, Direct .py execution
C,GCC compile → isolated binary run &lt;a href="https://theigknight.com/documentation/java/java-introduction" rel="noopener noreferrer"&gt;Java&lt;/a&gt;, javac → java run
&lt;a href="https://theigknight.com/documentation/csharp/csharp-introduction" rel="noopener noreferrer"&gt;C#&lt;/a&gt;, &lt;a href="https://theigknight.com/documentation/dotnet/dotnet-introduction" rel="noopener noreferrer"&gt;dotnet&lt;/a&gt; compile &amp;amp; execute&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For our C# language support, we utilize the official tools. If you are interested in exploring the language used for our high-performance backend, you can dive into the official &lt;a href="https://theigknight.com/documentation/csharp/csharp-introduction" rel="noopener noreferrer"&gt;C# language documentation&lt;/a&gt;.&lt;br&gt;
Each executes in a fresh sandbox for ultimate security.&lt;br&gt;
&lt;strong&gt;⚙ Execution Flow Example (.NET Core)&lt;/strong&gt;&lt;br&gt;
var file = CreateTempFile(request.Code, request.Language);&lt;br&gt;
var image = MapToDockerImage(request.Language);&lt;br&gt;
var result = ExecuteDocker(image, file, new SecureOptions&lt;br&gt;
{&lt;br&gt;
    TimeoutSeconds = 5,&lt;br&gt;
    MemoryLimitMb = 256&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;Cleanup(file);&lt;br&gt;
return result;&lt;/p&gt;

&lt;p&gt;We also loop through user test cases and return detailed feedback.&lt;br&gt;
&lt;strong&gt;🛡 Security Considerations&lt;/strong&gt;&lt;br&gt;
Security is paramount when running untrusted user code. Docker ensures complete filesystem isolation 🔒, acting as a crucial security layer.&lt;/p&gt;

&lt;p&gt;Threat,Solution&lt;br&gt;
Infinite loops,Global timeout limit&lt;br&gt;
Excess memory,RAM limits (Docker)&lt;br&gt;
System access attempt,Container with no host permissions&lt;br&gt;
Malware persistence,Destroy container after each run&lt;br&gt;
Sensitive data exposure,Output sanitization&lt;/p&gt;

&lt;p&gt;📈 Why This Architecture Scales&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stateless API = easy load balancing&lt;/li&gt;
&lt;li&gt;Containers pull pre-built language images&lt;/li&gt;
&lt;li&gt;High burst execution capacity&lt;/li&gt;
&lt;li&gt;Efficient cleanup → no leftover resource usage
We can handle 1000s of code executions per minute.
*&lt;em&gt;🎯 Experience the Compiler Live on Igknight
*&lt;/em&gt;
Want to try the full environment with a coding challenge?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The same compiler architecture described above powers our interactive tools: 👉 &lt;a href="https://theigknight.com/challenge" rel="noopener noreferrer"&gt;Try a C# Coding Challenge on Igknight&lt;/a&gt;&lt;br&gt;
Perfect for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Backend developers&lt;/li&gt;
&lt;li&gt;Students learning .NET&lt;/li&gt;
&lt;li&gt;Coding interview preparation&lt;/li&gt;
&lt;li&gt;Quick experiments without IDE setup&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks from the &lt;a href="https://theigknight.com/" rel="noopener noreferrer"&gt;Igknight Team!&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
