CM.Logging.AspNet
1.0.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package CM.Logging.AspNet --version 1.0.2
NuGet\Install-Package CM.Logging.AspNet -Version 1.0.2
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="CM.Logging.AspNet" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CM.Logging.AspNet" Version="1.0.2" />
<PackageReference Include="CM.Logging.AspNet" />
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 CM.Logging.AspNet --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CM.Logging.AspNet, 1.0.2"
#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 CM.Logging.AspNet@1.0.2
#: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=CM.Logging.AspNet&version=1.0.2
#tool nuget:?package=CM.Logging.AspNet&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
CM.Logger.AspNet
Extensión oficial para integrar CM.Logger en aplicaciones ASP.NET clásico (WebForms / MVC en .NET Framework 4.8).
Permite capturar automáticamente el contexto HTTP (HttpContext.Current) y enriquecer los logs con información relevante del request sin necesidad de código adicional en cada capa.
🚀 Instalación
Install-Package CM.Logger.AspNet
🧱 Requisitos
- .NET Framework 4.8
- Proyecto WebForms o MVC clásico
- Base de datos SQL Server
⚙️ Configuración
1. ConnectionString (web.config)
<connectionStrings>
<add name="DefaultConnection"
connectionString="Server=.;Database=CM_LOGS;Trusted_Connection=True;Encrypt=True;TrustServerCertificate=True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
2. Inicializar Logger (Global.asax.cs)
using System;
using System.Configuration;
using CM.Logger.AspNet.Helpers;
using CM.Logger.Models;
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
var conn = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
AppLoggerAspNetConfigurator.Configure(new LoggingOptions
{
ConnectionString = conn,
ApplicationName = "ClinicaCotizador",
EnvironmentName = "DEV",
ServerName = Environment.MachineName,
VersionApp = "1.0.0",
DefaultOrigen = "WEB",
CaptureMachineName = true,
CaptureEnvironmentUserName = false,
ThrowExceptions = false
});
}
}
🧠 Contexto capturado automáticamente
| Campo | Origen |
|---|---|
| Usuario | HttpContext.User.Identity |
| SessionId | HttpContext.Session |
| URL | Request.Url |
| Método | Request.HttpMethod |
| IP | UserHostAddress / Forwarded |
| UserAgent | Request.UserAgent |
| CorrelationId | Generado por request |
📝 Uso básico
AppLogger.LogInfo("Proceso ejecutado correctamente");
AppLogger.LogWarning("Validación incompleta");
AppLogger.LogError("Error en proceso", ex);
🧪 Ejemplo real (WebForms)
protected void btnGuardar_Click(object sender, EventArgs e)
{
try
{
// lógica de guardado
AppLogger.LogInfo("Se guardó correctamente la cotización");
}
catch (Exception ex)
{
AppLogger.LogError("Error al guardar cotización", ex);
throw;
}
}
🗄️ Base de datos (ejemplo tabla)
CREATE TABLE CM_LOGS (
Id BIGINT IDENTITY PRIMARY KEY,
Fecha DATETIME2 DEFAULT GETDATE(),
Nivel VARCHAR(20),
Mensaje NVARCHAR(MAX),
Excepcion NVARCHAR(MAX),
Usuario NVARCHAR(100),
Aplicacion NVARCHAR(100),
Entorno NVARCHAR(50),
IP NVARCHAR(50),
Url NVARCHAR(MAX),
Metodo NVARCHAR(10),
CorrelationId NVARCHAR(50)
);
⚙️ SP sugerido
CREATE PROCEDURE SP_INSERT_LOG
@Nivel VARCHAR(20),
@Mensaje NVARCHAR(MAX),
@Excepcion NVARCHAR(MAX),
@Usuario NVARCHAR(100),
@Aplicacion NVARCHAR(100),
@Entorno NVARCHAR(50),
@IP NVARCHAR(50),
@Url NVARCHAR(MAX),
@Metodo NVARCHAR(10),
@CorrelationId NVARCHAR(50)
AS
BEGIN
INSERT INTO CM_LOGS
VALUES (GETDATE(), @Nivel, @Mensaje, @Excepcion, @Usuario, @Aplicacion, @Entorno, @IP, @Url, @Metodo, @CorrelationId)
END
🔐 Buenas prácticas
- ❌ No loguear contraseñas
- ❌ No loguear tokens JWT completos
- ✔ Sanitizar headers sensibles
- ✔ Usar niveles correctamente
🧩 Arquitectura
- CM.Logger (core)
- CM.Logger.AspNet (context provider)
- SQL Server (persistencia)
📦 Dependencias
- CM.Logger
📄 Licencia
MIT
👨💻 Autor
CM, RogerSantos , CodeRS
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net48 is compatible. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.8
- 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.
Se genera una extension para compatibilidad de recursos web en 4.8