WriteToConsoleError 1.0.1

Suggested Alternatives

DotNetOutputToConsole

Additional Details

Adopt DotNetOutputToConsole to remove the existing dependency.

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package WriteToConsoleError --version 1.0.1
                    
NuGet\Install-Package WriteToConsoleError -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WriteToConsoleError" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WriteToConsoleError" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="WriteToConsoleError" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WriteToConsoleError --version 1.0.1
                    
#r "nuget: WriteToConsoleError, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WriteToConsoleError@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WriteToConsoleError&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=WriteToConsoleError&version=1.0.1
                    
Install as a Cake Tool

๐Ÿงฉ WriteToConsoleError

NuGet Version Build License: MIT

ASP.NET 4.8 utility that automatically writes unhandled server exceptions or custom messages to the browser console (console.error), with simple configuration and helper APIs.


๐Ÿš€ Features

โœ… Automatically logs unhandled server exceptions to browser console
โœ… Manually log exceptions or messages from your code-behind
โœ… Instantly inspect the current value of variables at runtime
โœ… Works in Web Forms or MVC (.NET Framework 4.8)
โœ… Toggleable via web.config
โœ… Optional stack trace output
โœ… Clean, dependency-free design
โœ… Includes unit tests + sample WebForms demo


๐Ÿ“ฆ Installation

Install from NuGet:

Install-Package WriteToConsoleError

or manually copy the DLL into your /bin folder.


โš™๏ธ Configuration (web.config)

<appSettings>
  <add key="WriteToConsoleError:Enabled" value="true" />
  <add key="WriteToConsoleError:ShowStack" value="false" />
</appSettings>

<system.webServer>
  <modules>
    <add name="WriteToConsoleErrorHttpModule"
         type="WriteToConsoleError.WriteToConsoleErrorHttpModule, WriteToConsoleError" />
  </modules>
</system.webServer>

The module injects JavaScript similar to:

<script>console.error('Server Error: [your message]');</script>

๐Ÿงฐ Manual Logging and Variable Inspection

Use WriteToConsoleErrorLogger anywhere in your code-behind to log exceptions, messages, or variable values directly to your browser console.

using WriteToConsoleError;

protected void Page_Load(object sender, EventArgs e)
{
    string username = "Alice";
    int orderCount = 5;

    // You can log any variable values for quick inspection:
    WriteToConsoleErrorLogger.LogMessage($"Current user: {username}");
    WriteToConsoleErrorLogger.LogMessage($"Orders today: {orderCount}");

    // Log an exception manually
    try
    {
        throw new Exception("Manual test exception");
    }
    catch (Exception ex)
    {
        WriteToConsoleErrorLogger.LogToBrowser(ex);
    }
}

Then open DevTools โ†’ Console tab in your browser to see:

Server Error: Current user: Alice
Server Error: Orders today: 5
Server Error: Manual test exception

This is extremely handy when debugging legacy WebForms or MVC apps โ€” no need for breakpoints or Response.Write.


๐Ÿงช Example Output

Server Error: Demo exception from Default.aspx Page_Load
Server Error: Current user: Alice
Server Error: Orders today: 5

๐Ÿงฉ How It Works

Component Responsibility
WriteToConsoleErrorHttpModule Hooks Application_Error and writes JavaScript console.error() output
WriteToConsoleErrorLogger Provides manual logging for messages, exceptions, and variable inspection
Config Reads web.config flags via System.Configuration.ConfigurationManager
WriteToConsoleEscaper Escapes characters safely for inline JavaScript strings

๐Ÿ“ Repository Structure

WriteToConsoleError/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ WriteToConsoleError/
โ”‚       โ”œโ”€โ”€ WriteToConsoleErrorHttpModule.cs
โ”‚       โ”œโ”€โ”€ WriteToConsoleErrorLogger.cs
โ”‚       โ”œโ”€โ”€ Internals.cs
โ”‚       โ””โ”€โ”€ WriteToConsoleError.csproj
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ WriteToConsoleError.Tests/
โ”œโ”€โ”€ samples/
โ”‚   โ””โ”€โ”€ WebFormsDemo/
โ””โ”€โ”€ README.md

๐Ÿงฐ Build & Test

dotnet restore
dotnet build -c Release
dotnet test  -c Release
dotnet pack  -c Release -o artifacts

Run the WebForms demo (set it as startup project in Visual Studio), open the browser console, and watch your server-side logs appear live.


๐Ÿงฉ Typical Use Cases

Scenario How to Use
Debug unhandled exceptions Let the HttpModule handle it automatically
Trace logic paths in code-behind WriteToConsoleErrorLogger.LogMessage("Reached step 3")
Check variable values WriteToConsoleErrorLogger.LogMessage($"cartCount = {cartCount}")
Debug production issues safely Disable ShowStack and leave Enabled=true

๐Ÿ”’ Security Notes

  • Do not enable ShowStack in production.
  • Use this primarily for development and QA environments.
  • For full logging, integrate a dedicated logger (Serilog/NLog).

๐Ÿค Contributing

Pull requests welcome!
Please ensure code follows SRP and includes matching unit tests.


๐Ÿชช License

MIT License ยฉ 2025 [Your Name]
See LICENSE for details.


Product Compatible and additional computed target framework versions.
.NET Framework net481 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.8.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated