ASP.NET Framework Integration
ByteHide Logger provides integration for traditional ASP.NET Framework applications, supporting both WebForms and MVC with automatic HTTP logging and exception capture.
Installation
Install the ASP.NET Framework integration package via NuGet:
Install-Package Bytehide.Logger.AspNet
Basic Configuration
Initialize ByteHide Logger in your Global.asax.cs
:
using Bytehide.Logger.AspNet.Extensions;
public class Global : System.Web.HttpApplication
{
protected void Application_Start()
{
// Initialize ByteHide Logger
this.InitializeBytehideLogging(options =>
{
options.ProjectToken = "your-project-token";
options.LogLevel = LogLevel.Info;
});
// Your other initialization code...
}
}
HTTP Module Registration
Register the HTTP module in your web.config
:
<configuration>
<system.webServer>
<modules>
<add name="BytehideLoggerHttpModule"
type="Bytehide.Logger.AspNet.Modules.BytehideLoggerHttpModule, Bytehide.Logger.AspNet" />
</modules>
</system.webServer>
</configuration>
Configuration Options
Basic Options
this.InitializeBytehideLogging(options =>
{
// Required
options.ProjectToken = "your-project-token";
// HTTP Logging
options.CaptureHttpRequests = true; // Log incoming requests
options.CaptureHttpResponses = true; // Log responses with timing
// Privacy
options.LogIpAddress = false; // Don't log client IPs
options.ExcludedHeaders = new[] { // Skip sensitive headers
"Authorization", "Cookie", "X-API-Key"
};
// Integration
options.ReplaceDefaultTracing = true; // Replace System.Diagnostics.Trace
options.CaptureMvcActions = true; // Log MVC controller actions
options.CaptureWebFormsLifecycle = false; // Log WebForms page events
options.LogLevel = LogLevel.Info; // Minimum log level
});
MVC Integration
Use ByteHide Logger in your MVC controllers:
using Bytehide.Logger.Core;
public class HomeController : Controller
{
public ActionResult Index()
{
Log.WithTags("mvc", "home")
.Info("Home page accessed");
return View();
}
public ActionResult About()
{
try
{
// Your logic here
return View();
}
catch (Exception ex)
{
Log.Error("Error in About page", ex);
return View("Error");
}
}
}
WebForms Integration
For automatic page lifecycle logging, inherit from the base page class:
using Bytehide.Logger.AspNet.WebForms;
public partial class Default : BytehideLoggerPage
{
protected void Page_Load(object sender, EventArgs e)
{
// Page events automatically logged
Log.WithTags("webforms", "page-load")
.Info("Default page loaded");
}
protected void Button_Click(object sender, EventArgs e)
{
Log.WithMetadata("buttonId", ((Button)sender).ID)
.Info("Button clicked");
}
}
System.Diagnostics.Trace Integration
When ReplaceDefaultTracing = true
, existing trace calls are forwarded to ByteHide Logger:
// These calls are automatically forwarded to ByteHide Logger
Trace.TraceInformation("Information message");
Trace.TraceWarning("Warning message");
Trace.TraceError("Error message");
Manual Logging
Use the core ByteHide Logger API anywhere in your application:
using Bytehide.Logger.Core;
// Simple logging
Log.Info("User logged in");
Log.Error("Database connection failed", exception);
// With context and tags
Log.WithTags("authentication", "security")
.WithMetadata("userId", userId)
.WithMetadata("source", "web")
.Info("User authentication successful");
Options Reference
Option | Type | Default | Description |
---|---|---|---|
ProjectToken | string | null | Your ByteHide project token |
CaptureHttpRequests | bool | true | Log incoming HTTP requests |
CaptureHttpResponses | bool | true | Log responses with timing |
LogIpAddress | bool | false | Include client IP addresses |
ExcludedHeaders | string[] | ["Authorization", "Cookie"] | Headers to exclude from logs |
ReplaceDefaultTracing | bool | true | Replace System.Diagnostics.Trace |
CaptureMvcActions | bool | true | Log MVC controller actions |
CaptureWebFormsLifecycle | bool | false | Log WebForms page lifecycle |
LogLevel | LogLevel | Warn | Minimum log level |
Supported Versions
- .NET Framework 4.6.2
- .NET Framework 4.7.2
- .NET Framework 4.8
Next Steps
- Configuration - Set up your project token
- Exception Handling - Learn about error logging
- Basic Logging - Core logging features