Skip to content

Commit f474427

Browse files
committed
Update the NuGet package after rearranging the folder structure.
1 parent 0f615eb commit f474427

21 files changed

+452
-270
lines changed

DotNetOutputToConsole.sln

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{02EA681E-C7D
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetOutputToConsole", "src\DotNetOutputToConsole\DotNetOutputToConsole.csproj", "{5FE20856-E888-465D-AD6A-F939E7F37774}"
1313
EndProject
14-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{DEA1D707-9B95-4B43-BA6F-F03508594B30}"
15-
EndProject
16-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo", "demo", "{243C3FB7-46CD-4108-B045-0B45F6BDC532}"
14+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}"
15+
ProjectSection(SolutionItems) = preProject
16+
LICENSE = LICENSE
17+
README.md = README.md
18+
EndProjectSection
1719
EndProject
18-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetOutputToConsole.Tests", "tests\DotNetOutputToConsole.Tests\DotNetOutputToConsole.Tests.csproj", "{8D2FAC39-F7E1-4892-916B-CD025CCF93AD}"
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetOutputToConsole.DemoWeb", "src\DotNetOutputToConsole.DemoWeb\DotNetOutputToConsole.DemoWeb.csproj", "{AB6B7FF4-20E1-4597-9932-3985E21E809E}"
1921
EndProject
20-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetOutputToConsole.DemoWeb", "demo\DotNetOutputToConsole.DemoWeb\DotNetOutputToConsole.DemoWeb.csproj", "{AB6B7FF4-20E1-4597-9932-3985E21E809E}"
22+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetOutputToConsole.Tests", "src\DotNetOutputToConsole.Tests\DotNetOutputToConsole.Tests.csproj", "{76C9B404-E1A4-8767-CB44-60D41E61B523}"
2123
EndProject
2224
Global
2325
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -29,22 +31,22 @@ Global
2931
{5FE20856-E888-465D-AD6A-F939E7F37774}.Debug|Any CPU.Build.0 = Debug|Any CPU
3032
{5FE20856-E888-465D-AD6A-F939E7F37774}.Release|Any CPU.ActiveCfg = Release|Any CPU
3133
{5FE20856-E888-465D-AD6A-F939E7F37774}.Release|Any CPU.Build.0 = Release|Any CPU
32-
{8D2FAC39-F7E1-4892-916B-CD025CCF93AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33-
{8D2FAC39-F7E1-4892-916B-CD025CCF93AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
34-
{8D2FAC39-F7E1-4892-916B-CD025CCF93AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
35-
{8D2FAC39-F7E1-4892-916B-CD025CCF93AD}.Release|Any CPU.Build.0 = Release|Any CPU
3634
{AB6B7FF4-20E1-4597-9932-3985E21E809E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3735
{AB6B7FF4-20E1-4597-9932-3985E21E809E}.Debug|Any CPU.Build.0 = Debug|Any CPU
3836
{AB6B7FF4-20E1-4597-9932-3985E21E809E}.Release|Any CPU.ActiveCfg = Release|Any CPU
3937
{AB6B7FF4-20E1-4597-9932-3985E21E809E}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{76C9B404-E1A4-8767-CB44-60D41E61B523}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{76C9B404-E1A4-8767-CB44-60D41E61B523}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{76C9B404-E1A4-8767-CB44-60D41E61B523}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{76C9B404-E1A4-8767-CB44-60D41E61B523}.Release|Any CPU.Build.0 = Release|Any CPU
4042
EndGlobalSection
4143
GlobalSection(SolutionProperties) = preSolution
4244
HideSolutionNode = FALSE
4345
EndGlobalSection
4446
GlobalSection(NestedProjects) = preSolution
4547
{5FE20856-E888-465D-AD6A-F939E7F37774} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
46-
{8D2FAC39-F7E1-4892-916B-CD025CCF93AD} = {DEA1D707-9B95-4B43-BA6F-F03508594B30}
47-
{AB6B7FF4-20E1-4597-9932-3985E21E809E} = {243C3FB7-46CD-4108-B045-0B45F6BDC532}
48+
{AB6B7FF4-20E1-4597-9932-3985E21E809E} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
49+
{76C9B404-E1A4-8767-CB44-60D41E61B523} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
4850
EndGlobalSection
4951
GlobalSection(ExtensibilityGlobals) = postSolution
5052
SolutionGuid = {9D4B5F62-CE47-46CB-8F03-2837F58A3F9F}

README.md

Lines changed: 74 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,55 @@
11
# DotNetOutputToConsole
22

3-
> 🧩 A secure ASP.NET Framework (4.8 / 4.8.1) helper library that writes logs, variables, and exceptions directly to the browser console — perfect for UAT and DEV environments.
3+
A secure ASP.NET Framework (4.8 / 4.8.1) helper library that writes logs, variables, and exceptions directly to the browser console — perfect for UAT and DEV environments.
44

5-
---
5+
## Features
6+
- Write messages, variables, and errors to the browser console (`console.info`, `console.log`, `console.error`)
7+
- Automatically logs unhandled exceptions globally
8+
- Works with any ASP.NET Web Forms or MVC project
9+
- Simple global toggle via `web.config`
10+
- XSS-safe using `System.Web.Helpers.Json.Encode` to sanitize all outputs
11+
- Zero third-party dependencies
12+
- Includes unit tests and a demo web app
13+
- Fully compatible with .NET Framework 4.8 to 4.8.1
614

7-
## ✨ Features
8-
- ✅ Write messages, variables, and errors to the browser console (`console.info`, `console.log`, `console.error`)
9-
- ✅ Automatically logs **unhandled exceptions** globally
10-
- ✅ Works with any **ASP.NET Web Forms** or **MVC** project
11-
- ✅ Simple global toggle via `web.config`
12-
-**XSS-safe** — uses `System.Web.Helpers.Json.Encode` to sanitize all outputs
13-
- ✅ Zero third-party dependencies
14-
- ✅ Includes **unit tests** and a **demo web app**
15-
- ✅ Fully compatible with **.NET Framework 4.8 → 4.8.1**
16-
17-
---
18-
19-
## ⚙️ Installation
20-
Install from NuGet using the .NET CLI or Visual Studio Package Manager Console:
15+
## Installation
16+
Install from NuGet using the Package Manager Console:
2117

2218
```powershell
2319
Install-Package DotNetOutputToConsole
2420
```
2521

26-
---
27-
28-
## 💡 Purpose
29-
When deploying ASP.NET apps to UAT or DEV servers, developers often need to see **runtime values** or **exceptions** directly in the browser console.
30-
This library provides a **safe, fast, and zero-config** way to do that, without changing your page layout or using intrusive alert popups.
22+
## Purpose
23+
When deploying ASP.NET applications to UAT or DEV environments, developers often need to inspect runtime values or exceptions directly in the browser console.
24+
This library provides a safe, fast, invisible way to do that without altering page UI or showing alert popups.
3125

3226
Example:
27+
3328
```csharp
3429
DotNetOutputToConsoleLogger.LogVariable("SessionId", Session.SessionID);
3530
DotNetOutputToConsoleLogger.LogError("Missing input data");
3631
```
3732

3833
Console output:
34+
3935
```
4036
LOG: SessionId: 1a2b3c4d
4137
ERROR: Missing input data
4238
```
4339

44-
---
40+
## Architecture Overview
4541

46-
## 🧠 Architecture Overview
4742
| Component | Description |
48-
|------------|--------------|
49-
| `DotNetOutputToConsoleLogger` | Core class that writes safe `<script>` tags to the HTTP response with sanitized console commands. |
50-
| `DotNetOutputToConsoleHttpModule` | Global ASP.NET module that automatically logs **unhandled exceptions** to the console. |
51-
| `web.config` switch | Toggle feature ON/OFF without recompiling. |
52-
| `Json.Encode()` | Ensures all messages are XSS-safe before rendering. |
43+
|----------|-------------|
44+
| `DotNetOutputToConsoleLogger` | Core class that writes sanitized console commands into browser output. |
45+
| `DotNetOutputToConsoleHttpModule` | Automatically logs unhandled exceptions at the application level. |
46+
| `web.config` switch | Allows turning console output on or off globally. |
47+
| `Json.Encode()` | Sanitizes all messages to avoid XSS or script injection. |
48+
49+
## Configuration
5350

54-
---
51+
Add the following to your Web.config:
5552

56-
## 📂 Configuration
57-
Add this to your **Web.config**:
5853
```xml
5954
<configuration>
6055
<appSettings>
@@ -63,37 +58,39 @@ Add this to your **Web.config**:
6358

6459
<system.webServer>
6560
<modules>
66-
<add name="DotNetOutputToConsoleHttpModule" type="DotNetOutputToConsole.DotNetOutputToConsoleHttpModule" />
61+
<add name="DotNetOutputToConsoleHttpModule"
62+
type="DotNetOutputToConsole.DotNetOutputToConsoleHttpModule" />
6763
</modules>
6864
</system.webServer>
6965
</configuration>
7066
```
7167

72-
Set `"EnableOutputToConsole"` to `"true"` in UAT/DEV.
73-
🚫 Set to `"false"` in production for performance and security.
68+
Set `"EnableOutputToConsole"` to `"true"` in UAT or DEV.
69+
Set to `"false"` in production.
7470

75-
---
71+
## Usage Examples
7672

77-
## 🧩 Usage Examples
78-
### 1️⃣ Log Information
73+
### Log Information
7974
```csharp
8075
DotNetOutputToConsoleLogger.LogInfo("Page load completed");
8176
```
82-
Console output:
77+
78+
Output:
8379
```
8480
INFO: Page load completed
8581
```
8682

87-
### 2️⃣ Log Variables
83+
### Log Variables
8884
```csharp
8985
DotNetOutputToConsoleLogger.LogVariable("Username", user.Name);
9086
```
91-
Console output:
87+
88+
Output:
9289
```
9390
LOG: Username: JohnDoe
9491
```
9592

96-
### 3️⃣ Log Exceptions
93+
### Log Exceptions
9794
```csharp
9895
try
9996
{
@@ -104,28 +101,28 @@ catch (Exception ex)
104101
DotNetOutputToConsoleLogger.LogError(ex.Message);
105102
}
106103
```
107-
Console output:
104+
105+
Output:
108106
```
109107
ERROR: Simulated failure
110108
```
111109

112-
### 4️⃣ Automatic Error Logging (No Try/Catch Needed)
113-
The built-in HTTP module automatically logs unhandled exceptions:
110+
### Automatic Error Logging (Unhandled Exceptions)
114111
```csharp
115112
protected void Page_Load(object sender, EventArgs e)
116113
{
117114
throw new Exception("Unhandled page error!");
118115
}
119116
```
120-
Console output:
117+
118+
Output:
121119
```
122120
ERROR: Unhandled Exception: Unhandled page error!
123121
```
124122

125-
---
123+
## Class Overview
126124

127-
## 🧩 Class Overview
128-
### 🔹 DotNetOutputToConsoleLogger.cs
125+
### DotNetOutputToConsoleLogger.cs
129126
```csharp
130127
public static class DotNetOutputToConsoleLogger
131128
{
@@ -134,10 +131,8 @@ public static class DotNetOutputToConsoleLogger
134131
public static void LogError(string message);
135132
}
136133
```
137-
All three use `Json.Encode()` internally to prevent XSS or script injection.
138134

139-
### 🔹 DotNetOutputToConsoleHttpModule.cs
140-
Automatically hooks into the ASP.NET pipeline:
135+
### DotNetOutputToConsoleHttpModule.cs
141136
```csharp
142137
public class DotNetOutputToConsoleHttpModule : IHttpModule
143138
{
@@ -153,54 +148,43 @@ public class DotNetOutputToConsoleHttpModule : IHttpModule
153148
}
154149
```
155150

156-
---
151+
## Security
157152

158-
## 🔒 Security
159-
| Protection | Description |
160-
|-------------|--------------|
161-
| **XSS Safe** | Uses `System.Web.Helpers.Json.Encode()` to escape any special characters before writing scripts. |
162-
| **Response-Safe** | Only writes inside valid `<script>` tags. |
163-
| **Config Toggle** | Easily disable all console output via Web.config. |
164-
| **Recommended Use** | Only enable in DEV or UAT environments. |
153+
| Feature | Description |
154+
|--------|-------------|
155+
| XSS Protection | All messages pass through `Json.Encode()` to escape special characters. |
156+
| Safe Output | Only writes inside valid `<script>` blocks. |
157+
| Config Toggle | Can be disabled instantly using Web.config. |
158+
| Recommended Usage | Enable only in UAT/DEV. |
165159

166-
---
160+
## Unit Testing
167161

168-
## 🧪 Unit Testing
169-
### Installation
162+
### Test Framework Installation
170163
```powershell
171164
Install-Package NUnit
172165
Install-Package NUnit3TestAdapter
173166
Install-Package Microsoft.NET.Test.Sdk
174167
```
168+
175169
### Example Test
176170
```csharp
177-
using NUnit.Framework;
178-
using DotNetOutputToConsole;
179-
180-
namespace DotNetOutputToConsole.Tests
171+
[Test]
172+
public void LogInfo_ShouldNotThrow()
181173
{
182-
[TestFixture]
183-
public class DotNetOutputToConsoleLoggerTests
184-
{
185-
[Test]
186-
public void LogInfo_ShouldNotThrow() => Assert.DoesNotThrow(() => DotNetOutputToConsoleLogger.LogInfo("info"));
187-
[Test]
188-
public void LogError_ShouldNotThrow() => Assert.DoesNotThrow(() => DotNetOutputToConsoleLogger.LogError("error"));
189-
[Test]
190-
public void LogVariable_ShouldNotThrow() => Assert.DoesNotThrow(() => DotNetOutputToConsoleLogger.LogVariable("Key", "Value"));
191-
}
174+
Assert.DoesNotThrow(() => DotNetOutputToConsoleLogger.LogInfo("info"));
192175
}
193176
```
177+
194178
### Run Tests
195-
In Visual Studio 2022 → **Test → Test Explorer → Run All Tests**
179+
Visual Studio 2022 → Test Explorer → Run All Tests
196180
or CLI:
181+
197182
```bash
198-
dotnet test tests/DotNetOutputToConsole.Tests/DotNetOutputToConsole.Tests.csproj
183+
dotnet test
199184
```
200185

201-
---
186+
## Project Structure
202187

203-
## 🧱 Project Structure
204188
```
205189
DotNetOutputToConsole/
206190
├── src/
@@ -221,37 +205,16 @@ DotNetOutputToConsole/
221205
└── DotNetOutputToConsoleLoggerTests.cs
222206
```
223207

224-
---
225-
226-
## 🧩 How It Works
227-
1. `DotNetOutputToConsoleLogger` calls `HttpContext.Current.Response.Write(...)`
228-
2. It injects a `<script>` tag that runs a console command like:
229-
```html
230-
<script>console.log("Your message");</script>
231-
```
232-
3. All messages are escaped via `Json.Encode()`.
233-
4. View messages in browser **Developer Tools → Console tab**.
208+
## How It Works
209+
1. The logger injects `<script>` tags into the HTTP response.
210+
2. Messages are encoded using `Json.Encode()` to prevent script injection.
211+
3. Output executes inside the browser console.
212+
4. View results using Developer Tools → Console.
234213

235-
---
214+
## Author
215+
Created by: **livedcode**
216+
GitHub: https://github.com/livedcode
217+
NuGet: https://www.nuget.org/profiles/livedcode
236218

237-
## 🧑‍💻 Author
238-
**Created by:** `livedcode`
239-
GitHub: [https://github.com/livedcode](https://github.com/livedcode)
240-
NuGet: [https://www.nuget.org/profiles/livedcode](https://www.nuget.org/profiles/livedcode)
241-
242-
---
243-
244-
## 📜 License
219+
## License
245220
MIT License © 2025 livedcode
246-
247-
---
248-
249-
## 🧭 Future Enhancements
250-
- Add `LogWarning()``console.warn()`
251-
- Dual logging (console + file)
252-
- ASP.NET Core middleware support
253-
- MVC exception filter integration
254-
255-
---
256-
257-
> 💡 “The simplest and safest way to see your ASP.NET logs in the browser console.”

0 commit comments

Comments
 (0)