TeaMonkeyFruit.Logger
1.2.0
See the version list below for details.
dotnet add package TeaMonkeyFruit.Logger --version 1.2.0
NuGet\Install-Package TeaMonkeyFruit.Logger -Version 1.2.0
<PackageReference Include="TeaMonkeyFruit.Logger" Version="1.2.0" />
paket add TeaMonkeyFruit.Logger --version 1.2.0
#r "nuget: TeaMonkeyFruit.Logger, 1.2.0"
// Install TeaMonkeyFruit.Logger as a Cake Addin #addin nuget:?package=TeaMonkeyFruit.Logger&version=1.2.0 // Install TeaMonkeyFruit.Logger as a Cake Tool #tool nuget:?package=TeaMonkeyFruit.Logger&version=1.2.0
TeaMonkeyFruit.Logger
A custom logging wrapper for creating logs in the Google Cloud Platform StackDriver LogEntry
structure using serilog and Google.Cloud.Diagnostics in Asp.Net Core 2
When hosting services in GCP, a request includes a X-Cloud-Trace-Context
header. The trace and spanId are retrieved from this header and added to the CustomStackdriverLogger
Context. Logs made with the CustomStackdriverLogger have the trace and spanId added to them, allowing them to be coorelated with the Trace requests in the StackDriver Trace View. This shows the logs nested in under the trace requests in the Trace View. The logs are structured according to the LogEntry
spec defined by Google StackDriver enabling the LoggingAPI to parse them and recoginize the special fields. reference: (https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry).
Example Use:
Register the StackDriverFormatter (Serilog.JsonValueFormatter)
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Console(new StackDriverFormatter()) // <-- Pass StackDriverFormatter to Console()
.CreateLogger();
Add the Custom Logger
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
...
services.AddCustomStackdriverLogger("myGoogleProjectId");
...
}
}
Inject into constructor to use:
public class Repository
{
private readonly ICustomStackdriverLogger _customStackdriverLogger;
public Repository(ICustomStackdriverLogger customStackdriverLogger)
{
_customStackdriverLogger = customStackdriverLogger;
}
public Item GetItem(int id)
{
var item = Database.GetItem(id);
_customStackdriverLogger.LogInformation<Repository>(message: $"Getting item of type: {typeof(Item).Name} in {nameof(GetItem)}", item);
return item;
}
}
Log structure will be:
{
insertId: "5da6c3a200j0923bx23x2"
jsonPayload: {
ConnectionId: "0HJ9R3489J98FM"
CorrelationId: null
RequestId: "0H93489F34HJM:00000001"
RequestPath: "/graphql"
message: "Getting Collection of type: FakeItem in GetCollectionOfItemsAsync"
messageTemplate: "Getting Collection of type: FakeItem in GetCollectionOfItemsAsync"
spanId: "4560986706170855936"
timestamp: "2019-10-16T07:15:46.8713740Z"
}
labels: {
instanceId: "00bf4bf02d34e072dc1c49x8dj943x4b5609mubm0409u566ad08acf6283d2b5135651fd8f2633e7b06e7dde4b96cfddbf5373a642da0b65fb21cf87a5aad"
}
logName: "projects/myProject/logs/run.googleapis.com%2Fstdout"
receiveTimestamp: "2019-10-16T07:15:47.113845061Z"
resource: {
labels: {
configuration_name: "baseproject-graphql"
location: "us-central1"
project_id: "myProject"
revision_name: "baseproject-graphql-vhglp"
service_name: "baseproject-graphql"
}
type: "cloud_run_revision"
}
timestamp: "2019-10-16T07:15:46.871489Z"
severity: "INFO"
trace: "projects/myProject/traces/04b4a840df0289bb9fddcd62235d3ee4"
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Google.Cloud.Diagnostics.AspNetCore (>= 3.0.0-beta14)
- Microsoft.AspNetCore (>= 2.2.0)
- Serilog.AspNetCore (>= 3.1.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TeaMonkeyFruit.Logger:
Package | Downloads |
---|---|
TeaMonkeyFruit.ServiceAuthentication
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.