/

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

OptionTypeDefaultDescription
ProjectTokenstringnullYour ByteHide project token
CaptureHttpRequestsbooltrueLog incoming HTTP requests
CaptureHttpResponsesbooltrueLog responses with timing
LogIpAddressboolfalseInclude client IP addresses
ExcludedHeadersstring[]["Authorization", "Cookie"]Headers to exclude from logs
ReplaceDefaultTracingbooltrueReplace System.Diagnostics.Trace
CaptureMvcActionsbooltrueLog MVC controller actions
CaptureWebFormsLifecycleboolfalseLog WebForms page lifecycle
LogLevelLogLevelWarnMinimum log level

Supported Versions

  • .NET Framework 4.6.2
  • .NET Framework 4.7.2
  • .NET Framework 4.8

Next Steps

Previous
ASP.NET Core