foundry-log
1.8.0
See the version list below for details.
dotnet add package foundry-log --version 1.8.0
NuGet\Install-Package foundry-log -Version 1.8.0
<PackageReference Include="foundry-log" Version="1.8.0" />
<PackageVersion Include="foundry-log" Version="1.8.0" />
<PackageReference Include="foundry-log" />
paket add foundry-log --version 1.8.0
#r "nuget: foundry-log, 1.8.0"
#:package foundry-log@1.8.0
#addin nuget:?package=foundry-log&version=1.8.0
#tool nuget:?package=foundry-log&version=1.8.0
foundry-log
HTTP request/response logging middleware for ASP.NET Core APIs, plus application logging for console apps. Captures metadata and posts it as JSON to the Foundry Log API.
Installation
Install the package:
dotnet add package foundry-log
Setup
All three parameters are required:
| Parameter | Description |
|---|---|
service |
Identifies the service sending the logs |
apiUrl |
Base URL of the Foundry Log API |
apiKey |
API key sent via the x-api-key header |
ASP.NET Core API Logging
builder.Services.AddFoundryLog(
service: "my-api-service",
apiUrl: "https://test.com/v1/foundrylog",
apiKey: "your-api-key"
);
var app = builder.Build();
app.UseFoundryLog();
Console App Logging
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddFoundryLog(
service: "my-console-app",
apiUrl: "https://test.com/v1/foundrylog",
apiKey: "your-api-key"
);
services.AddScoped<MyAppService>();
})
.Build();
var appService = host.Services.GetRequiredService<MyAppService>();
Configuration
builder.Services.AddFoundryLog(
service: "my-api-service",
apiUrl: "https://test.com/v1/foundrylog",
apiKey: "your-api-key",
options =>
{
// When true, log dispatch runs in the background and won't delay responses.
// Use false for AWS Lambda, true for long-running hosts (IIS, Kestrel).
// Default: false
options.FireAndForget = true;
// Which log levels to send. Default: Slow | Warn | Error (info is excluded).
options.SendLevels = FoundryLogLevel.Slow | FoundryLogLevel.Warn | FoundryLogLevel.Error;
// To include all levels:
// options.SendLevels = FoundryLogLevel.All;
// Duration threshold in ms for "slow" classification. Default: 1200.
options.SlowThresholdMs = 1200;
// HTTP status codes to ignore entirely (API logging only).
options.IgnoreStatusCodes = [404];
// Endpoints to exclude from logging (API logging only).
// Supports exact matches and wildcard patterns.
options.IgnoreEndpoints =
[
new IgnoreEndpoint("/v1/health"), // ignore for all levels
new IgnoreEndpoint("/v2/*"), // ignore for all levels
new IgnoreEndpoint("/swagger/*"), // ignore for all levels
new IgnoreEndpoint("/v1/polls", FoundryLogLevel.Info), // ignore only info-level logs
new IgnoreEndpoint("/v1/feed/*",
FoundryLogLevel.Info | FoundryLogLevel.Slow) // ignore info and slow
];
}
);
Log Levels
API Requests
Each request is classified into a log level:
| Level | Condition |
|---|---|
error |
Status code 500+ |
warn |
Status code 400–499 |
slow |
Status code < 400 but duration exceeds threshold |
info |
Status code < 400 and within threshold |
Console App Operations
Each operation is classified based on result code:
| Level | Condition |
|---|---|
error |
ResultCode = 0 (failure) |
slow |
ResultCode = 1 and duration exceeds threshold |
info |
ResultCode = 1 and within threshold |
By default, only slow, warn, and error logs are sent.
What Gets Logged
API Requests
{
"service": "my-api-service",
"method": "GET",
"path": "/api/users/123",
"queryString": "filter=active",
"statusCode": 200,
"durationMs": 245,
"ip": "192.168.1.100",
"origin": "https://example.com",
"userAgent": "Mozilla/5.0...",
"platform": "web",
"level": "info",
"exception": null,
"innerException": null,
"requestId": "00-abc123...-xyz789...-00",
"timestamp": "2024-03-27T10:30:00Z"
}
Console App Operations
{
"service": "my-console-app",
"appName": "DataProcessor",
"functionName": "ProcessUserAsync",
"arguments": "{\"userId\":123,\"email\":\"user@example.com\"}",
"brandId": 1,
"resultCode": 1,
"durationMs": 350,
"level": "info",
"exception": null,
"innerException": null,
"requestId": "550e8400-e29b-41d4-a716-446655440000",
"timestamp": "2024-03-27T10:30:00Z"
}
Console App Logging
Use the injected FoundryAppLogger service to log operations in your console app:
public class DataProcessor
{
private readonly FoundryAppLogger _appLogger;
public DataProcessor(FoundryAppLogger appLogger)
{
_appLogger = appLogger;
}
// Async operation with return value
public async Task<User> ProcessUserAsync(int userId, string email, int? brandId = null)
{
return await _appLogger.LogCallAsync(
appName: "DataProcessor",
functionName: "ProcessUserAsync",
arguments: JsonSerializer.Serialize(new { userId, email }),
brandId: brandId,
operation: async () =>
{
var user = await FetchUserAsync(userId);
user.Email = email;
await SaveUserAsync(user);
return user;
}
);
}
// Async operation without return
public async Task SendNotificationAsync(int userId, string message, int? brandId = null)
{
await _appLogger.LogCallAsync(
appName: "DataProcessor",
functionName: "SendNotificationAsync",
arguments: JsonSerializer.Serialize(new { userId, message }),
brandId: brandId,
operation: async () =>
{
await _emailService.SendAsync(userId, message);
}
);
}
// Sync operation with return
public bool ValidateEmail(string email, int? brandId = null)
{
return _appLogger.LogCall(
appName: "DataProcessor",
functionName: "ValidateEmail",
arguments: JsonSerializer.Serialize(new { email }),
brandId: brandId,
operation: () => email.Contains("@") && email.Contains(".")
);
}
// Sync operation without return
public void LogAuditTrail(int userId, string action, int? brandId = null)
{
_appLogger.LogCall(
appName: "DataProcessor",
functionName: "LogAuditTrail",
arguments: JsonSerializer.Serialize(new { userId, action }),
brandId: brandId,
operation: () =>
{
_auditService.Log(userId, action);
}
);
}
}
FoundryAppLogger API
The FoundryAppLogger service provides four overloads for flexible operation logging:
// Async with return value
Task<T> LogCallAsync<T>(
string appName,
string functionName,
string? arguments = null,
int? brandId = null,
Func<Task<T>>? operation = null)
// Async without return
Task LogCallAsync(
string appName,
string functionName,
string? arguments = null,
int? brandId = null,
Func<Task>? operation = null)
// Sync with return value
T LogCall<T>(
string appName,
string functionName,
string? arguments = null,
int? brandId = null,
Func<T>? operation = null)
// Sync without return
void LogCall(
string appName,
string functionName,
string? arguments = null,
int? brandId = null,
Action? operation = null)
All overloads automatically:
- Time the operation
- Set
ResultCode = 1on success orResultCode = 0on exception - Capture exception messages
- Classify the log level based on duration and result code
- Send the log entry to the Foundry Log API
Supported Frameworks
- .NET 8
- .NET 10
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net8.0
- 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.