From 62d1d87b4cac8d3691026156505fd2d05478b38c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E6=B3=BD=E5=A8=81?= <1585955375@qq.com>
Date: Thu, 1 Sep 2022 15:13:33 +0800
Subject: [PATCH 1/3] feat : Add logging to skywalking
---
skyapm-dotnet.sln | 7 +++
.../SkyApm.Diagnostics.Logging.csproj | 14 ++++++
.../SkyApmLogger.cs | 45 +++++++++++++++++++
.../SkyApmLoggerExtensions.cs | 16 +++++++
.../SkyApmLoggerProvider.cs | 32 +++++++++++++
5 files changed, 114 insertions(+)
create mode 100644 src/SkyApm.Diagnostics.Logging/SkyApm.Diagnostics.Logging.csproj
create mode 100644 src/SkyApm.Diagnostics.Logging/SkyApmLogger.cs
create mode 100644 src/SkyApm.Diagnostics.Logging/SkyApmLoggerExtensions.cs
create mode 100644 src/SkyApm.Diagnostics.Logging/SkyApmLoggerProvider.cs
diff --git a/skyapm-dotnet.sln b/skyapm-dotnet.sln
index aac867d6..168bb4c4 100644
--- a/skyapm-dotnet.sln
+++ b/skyapm-dotnet.sln
@@ -109,6 +109,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Diagnostics.FreeSql"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Sample.FreeSqlSqlite", "sample\SkyApm.Sample.FreeSql\SkyApm.Sample.FreeSqlSqlite.csproj", "{B1EF3295-4BF0-489F-8063-C9E3DAE20AA9}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkyApm.Diagnostics.Logging", "src\SkyApm.Diagnostics.Logging\SkyApm.Diagnostics.Logging.csproj", "{4E3BA76C-2A30-4CAD-9F6C-08DF5DF0CE0C}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -243,6 +245,10 @@ Global
{B1EF3295-4BF0-489F-8063-C9E3DAE20AA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1EF3295-4BF0-489F-8063-C9E3DAE20AA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1EF3295-4BF0-489F-8063-C9E3DAE20AA9}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4E3BA76C-2A30-4CAD-9F6C-08DF5DF0CE0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4E3BA76C-2A30-4CAD-9F6C-08DF5DF0CE0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4E3BA76C-2A30-4CAD-9F6C-08DF5DF0CE0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4E3BA76C-2A30-4CAD-9F6C-08DF5DF0CE0C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -289,6 +295,7 @@ Global
{8D3C5573-C282-45F5-A7F4-2E323F322CB7} = {B5E677CF-2920-4B0A-A056-E73F6B2CF2BC}
{82580A47-9DBC-43E8-B581-0C35147B4FAD} = {B5E677CF-2920-4B0A-A056-E73F6B2CF2BC}
{B1EF3295-4BF0-489F-8063-C9E3DAE20AA9} = {844CEACD-4C85-4B15-9E2B-892B01FDA4BB}
+ {4E3BA76C-2A30-4CAD-9F6C-08DF5DF0CE0C} = {B5E677CF-2920-4B0A-A056-E73F6B2CF2BC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {94C0DA2C-CCCB-4314-93A2-9809B5DD0583}
diff --git a/src/SkyApm.Diagnostics.Logging/SkyApm.Diagnostics.Logging.csproj b/src/SkyApm.Diagnostics.Logging/SkyApm.Diagnostics.Logging.csproj
new file mode 100644
index 00000000..f4f42d79
--- /dev/null
+++ b/src/SkyApm.Diagnostics.Logging/SkyApm.Diagnostics.Logging.csproj
@@ -0,0 +1,14 @@
+
+
+
+ netcoreapp3.1;net5.0;net6.0
+ enable
+
+
+
+
+
+
+
+
+
diff --git a/src/SkyApm.Diagnostics.Logging/SkyApmLogger.cs b/src/SkyApm.Diagnostics.Logging/SkyApmLogger.cs
new file mode 100644
index 00000000..09afb7e9
--- /dev/null
+++ b/src/SkyApm.Diagnostics.Logging/SkyApmLogger.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using Microsoft.Extensions.Logging;
+using SkyApm.Tracing;
+using SkyApm.Tracing.Segments;
+using SkyApm.Transport;
+
+namespace SkyApm.Diagnostics.Logging
+{
+ public class SkyApmLogger:ILogger
+ {
+ private readonly string _categoryName;
+ private readonly ISkyApmLogDispatcher _skyApmLogDispatcher;
+ private readonly IEntrySegmentContextAccessor _entrySegmentContextAccessor;
+ public SkyApmLogger(string categoryName, ISkyApmLogDispatcher skyApmLogDispatcher, IEntrySegmentContextAccessor entrySegmentContextAccessor)
+ {
+ _categoryName = categoryName;
+ _skyApmLogDispatcher = skyApmLogDispatcher;
+ _entrySegmentContextAccessor = entrySegmentContextAccessor;
+ }
+
+ public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter)
+ {
+ if (true)
+ {
+ var logs = new Dictionary();
+ logs.Add("className", _categoryName);
+ logs.Add("Level", logLevel);
+ logs.Add("logMessage", state.ToString()??"");
+ var logContext = new LoggerContext()
+ {
+ Logs = logs,
+ SegmentContext = _entrySegmentContextAccessor.Context,
+ };
+ _skyApmLogDispatcher.Dispatch(logContext);
+ }
+ }
+
+ public bool IsEnabled(LogLevel logLevel)=>true;
+
+
+ public IDisposable BeginScope(TState state)=> default!;
+ }
+}
+
diff --git a/src/SkyApm.Diagnostics.Logging/SkyApmLoggerExtensions.cs b/src/SkyApm.Diagnostics.Logging/SkyApmLoggerExtensions.cs
new file mode 100644
index 00000000..38fc37c3
--- /dev/null
+++ b/src/SkyApm.Diagnostics.Logging/SkyApmLoggerExtensions.cs
@@ -0,0 +1,16 @@
+using Microsoft.Extensions.DependencyInjection.Extensions;
+using Microsoft.Extensions.Logging;
+using SkyApm.Diagnostics.Logging;
+
+namespace Microsoft.Extensions.DependencyInjection
+{
+ public static class SkyApmLoggerExtensions
+ {
+ public static IServiceCollection AddSkyApmLogger(this IServiceCollection service)
+ {
+ service.TryAddEnumerable(ServiceDescriptor.Singleton());
+ return service;
+ }
+ }
+}
+
diff --git a/src/SkyApm.Diagnostics.Logging/SkyApmLoggerProvider.cs b/src/SkyApm.Diagnostics.Logging/SkyApmLoggerProvider.cs
new file mode 100644
index 00000000..b999f2a7
--- /dev/null
+++ b/src/SkyApm.Diagnostics.Logging/SkyApmLoggerProvider.cs
@@ -0,0 +1,32 @@
+using System.Collections.Concurrent;
+using Microsoft.Extensions.Logging;
+using SkyApm.Tracing;
+using SkyApm.Transport;
+
+namespace SkyApm.Diagnostics.Logging
+{
+ public class SkyApmLoggerProvider: ILoggerProvider
+ {
+ private ConcurrentDictionary _doveLoggers = new ConcurrentDictionary();
+ private readonly ISkyApmLogDispatcher _skyApmLogDispatcher;
+ private readonly IEntrySegmentContextAccessor _entrySegmentContextAccessor;
+
+ public SkyApmLoggerProvider(ISkyApmLogDispatcher skyApmLogDispatcher,IEntrySegmentContextAccessor entrySegmentContextAccessor)
+ {
+ _skyApmLogDispatcher = skyApmLogDispatcher;
+ _entrySegmentContextAccessor = entrySegmentContextAccessor;
+
+ }
+
+ public void Dispose()
+ {
+
+ }
+
+ public ILogger CreateLogger(string categoryName)
+ {
+ return _doveLoggers.GetOrAdd(categoryName,_=>new SkyApmLogger(categoryName,_skyApmLogDispatcher,_entrySegmentContextAccessor));
+ }
+ }
+}
+
From ccaf725ee38d7ffd20c098085172302f129e5b89 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E6=B3=BD=E5=A8=81?= <1585955375@qq.com>
Date: Sat, 3 Sep 2022 20:30:18 +0800
Subject: [PATCH 2/3] feat : Modify class library name
---
.../Controllers/WeatherForecastController.cs | 34 +++++++++++++++++
sample/SkyApm.Sample.Logging/Program.cs | 25 +++++++++++++
.../Properties/launchSettings.json | 15 ++++++++
.../SkyApm.Sample.Logging.csproj | 20 ++++++++++
.../SkyApm.Sample.Logging/WeatherForecast.cs | 12 ++++++
.../appsettings.Development.json | 8 ++++
sample/SkyApm.Sample.Logging/appsettings.json | 9 +++++
sample/SkyApm.Sample.Logging/skyapm.json | 30 +++++++++++++++
skyapm-dotnet.sln | 9 ++++-
.../Extensions/ServiceCollectionExtensions.cs | 6 ++-
.../SkyApm.Agent.Hosting.csproj | 37 ++++++++++---------
.../SkyApmLoggerExtensions.cs | 16 --------
.../SkyApm.Diagnostics.MSLogging.csproj} | 1 +
.../SkyApmLogger.cs | 35 ++++++++----------
.../SkyApmLoggerProvider.cs | 2 +-
15 files changed, 203 insertions(+), 56 deletions(-)
create mode 100644 sample/SkyApm.Sample.Logging/Controllers/WeatherForecastController.cs
create mode 100644 sample/SkyApm.Sample.Logging/Program.cs
create mode 100644 sample/SkyApm.Sample.Logging/Properties/launchSettings.json
create mode 100644 sample/SkyApm.Sample.Logging/SkyApm.Sample.Logging.csproj
create mode 100644 sample/SkyApm.Sample.Logging/WeatherForecast.cs
create mode 100644 sample/SkyApm.Sample.Logging/appsettings.Development.json
create mode 100644 sample/SkyApm.Sample.Logging/appsettings.json
create mode 100644 sample/SkyApm.Sample.Logging/skyapm.json
delete mode 100644 src/SkyApm.Diagnostics.Logging/SkyApmLoggerExtensions.cs
rename src/{SkyApm.Diagnostics.Logging/SkyApm.Diagnostics.Logging.csproj => SkyApm.Diagnostics.MSLogging/SkyApm.Diagnostics.MSLogging.csproj} (89%)
rename src/{SkyApm.Diagnostics.Logging => SkyApm.Diagnostics.MSLogging}/SkyApmLogger.cs (55%)
rename src/{SkyApm.Diagnostics.Logging => SkyApm.Diagnostics.MSLogging}/SkyApmLoggerProvider.cs (96%)
diff --git a/sample/SkyApm.Sample.Logging/Controllers/WeatherForecastController.cs b/sample/SkyApm.Sample.Logging/Controllers/WeatherForecastController.cs
new file mode 100644
index 00000000..585a15f1
--- /dev/null
+++ b/sample/SkyApm.Sample.Logging/Controllers/WeatherForecastController.cs
@@ -0,0 +1,34 @@
+using Microsoft.AspNetCore.Mvc;
+
+namespace SkyApm.Sample.Logging.Controllers;
+
+[ApiController]
+[Route("[controller]")]
+public class WeatherForecastController : ControllerBase
+{
+ private static readonly string[] Summaries = new[]
+ {
+ "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
+ };
+
+ private readonly ILogger _logger;
+
+ public WeatherForecastController(ILogger logger)
+ {
+ _logger = logger;
+ }
+
+ [HttpGet(Name = "GetWeatherForecast")]
+ public IEnumerable Get()
+ {
+ _logger.LogInformation("查询时间");
+
+ return Enumerable.Range(1, 5).Select(index => new WeatherForecast
+ {
+ Date = DateTime.Now.AddDays(index),
+ TemperatureC = Random.Shared.Next(-20, 55),
+ Summary = Summaries[Random.Shared.Next(Summaries.Length)]
+ })
+ .ToArray();
+ }
+}
\ No newline at end of file
diff --git a/sample/SkyApm.Sample.Logging/Program.cs b/sample/SkyApm.Sample.Logging/Program.cs
new file mode 100644
index 00000000..8264bac5
--- /dev/null
+++ b/sample/SkyApm.Sample.Logging/Program.cs
@@ -0,0 +1,25 @@
+var builder = WebApplication.CreateBuilder(args);
+
+// Add services to the container.
+
+builder.Services.AddControllers();
+// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
+builder.Services.AddEndpointsApiExplorer();
+builder.Services.AddSwaggerGen();
+
+var app = builder.Build();
+
+// Configure the HTTP request pipeline.
+if (app.Environment.IsDevelopment())
+{
+ app.UseSwagger();
+ app.UseSwaggerUI();
+}
+
+app.UseHttpsRedirection();
+
+app.UseAuthorization();
+
+app.MapControllers();
+
+app.Run();
\ No newline at end of file
diff --git a/sample/SkyApm.Sample.Logging/Properties/launchSettings.json b/sample/SkyApm.Sample.Logging/Properties/launchSettings.json
new file mode 100644
index 00000000..c87edda9
--- /dev/null
+++ b/sample/SkyApm.Sample.Logging/Properties/launchSettings.json
@@ -0,0 +1,15 @@
+{
+ "profiles": {
+ "SkyApm.Sample.Logging": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "launchUrl": "swagger",
+ "applicationUrl": "https://localhost:7126;http://localhost:5021",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development",
+ "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "SkyAPM.Agent.AspNetCore"
+ }
+ }
+ }
+}
diff --git a/sample/SkyApm.Sample.Logging/SkyApm.Sample.Logging.csproj b/sample/SkyApm.Sample.Logging/SkyApm.Sample.Logging.csproj
new file mode 100644
index 00000000..f54d89f7
--- /dev/null
+++ b/sample/SkyApm.Sample.Logging/SkyApm.Sample.Logging.csproj
@@ -0,0 +1,20 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+ Always
+
+
+
diff --git a/sample/SkyApm.Sample.Logging/WeatherForecast.cs b/sample/SkyApm.Sample.Logging/WeatherForecast.cs
new file mode 100644
index 00000000..63e0dc12
--- /dev/null
+++ b/sample/SkyApm.Sample.Logging/WeatherForecast.cs
@@ -0,0 +1,12 @@
+namespace SkyApm.Sample.Logging;
+
+public class WeatherForecast
+{
+ public DateTime Date { get; set; }
+
+ public int TemperatureC { get; set; }
+
+ public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
+
+ public string? Summary { get; set; }
+}
\ No newline at end of file
diff --git a/sample/SkyApm.Sample.Logging/appsettings.Development.json b/sample/SkyApm.Sample.Logging/appsettings.Development.json
new file mode 100644
index 00000000..0c208ae9
--- /dev/null
+++ b/sample/SkyApm.Sample.Logging/appsettings.Development.json
@@ -0,0 +1,8 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ }
+}
diff --git a/sample/SkyApm.Sample.Logging/appsettings.json b/sample/SkyApm.Sample.Logging/appsettings.json
new file mode 100644
index 00000000..10f68b8c
--- /dev/null
+++ b/sample/SkyApm.Sample.Logging/appsettings.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ },
+ "AllowedHosts": "*"
+}
diff --git a/sample/SkyApm.Sample.Logging/skyapm.json b/sample/SkyApm.Sample.Logging/skyapm.json
new file mode 100644
index 00000000..80b467f7
--- /dev/null
+++ b/sample/SkyApm.Sample.Logging/skyapm.json
@@ -0,0 +1,30 @@
+{
+ "SkyWalking": {
+ "ServiceName": "asp-net-core-backend-logging",
+ "Namespace": "",
+ "HeaderVersions": [
+ "sw8"
+ ],
+ "Sampling": {
+ "SamplePer3Secs": -1,
+ "Percentage": -1.0,
+ "LogSqlParameterValue": false
+ },
+ "Logging": {
+ "Level": "Information",
+ "FilePath": "logs/skyapm-{Date}.log"
+ },
+ "Transport": {
+ "Interval": 3000,
+ "ProtocolVersion": "v8",
+ "QueueSize": 30000,
+ "BatchSize": 3000,
+ "gRPC": {
+ "Servers": "192.168.31.10:30102",
+ "Timeout": 100000,
+ "ConnectTimeout": 100000,
+ "ReportTimeout": 600000
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/skyapm-dotnet.sln b/skyapm-dotnet.sln
index 168bb4c4..811e3674 100644
--- a/skyapm-dotnet.sln
+++ b/skyapm-dotnet.sln
@@ -109,7 +109,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Diagnostics.FreeSql"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Sample.FreeSqlSqlite", "sample\SkyApm.Sample.FreeSql\SkyApm.Sample.FreeSqlSqlite.csproj", "{B1EF3295-4BF0-489F-8063-C9E3DAE20AA9}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkyApm.Diagnostics.Logging", "src\SkyApm.Diagnostics.Logging\SkyApm.Diagnostics.Logging.csproj", "{4E3BA76C-2A30-4CAD-9F6C-08DF5DF0CE0C}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkyApm.Diagnostics.MSLogging", "src\SkyApm.Diagnostics.MSLogging\SkyApm.Diagnostics.MSLogging.csproj", "{4E3BA76C-2A30-4CAD-9F6C-08DF5DF0CE0C}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkyApm.Sample.Logging", "sample\SkyApm.Sample.Logging\SkyApm.Sample.Logging.csproj", "{136EAD07-A501-4308-9972-82E44F655735}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -249,6 +251,10 @@ Global
{4E3BA76C-2A30-4CAD-9F6C-08DF5DF0CE0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E3BA76C-2A30-4CAD-9F6C-08DF5DF0CE0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E3BA76C-2A30-4CAD-9F6C-08DF5DF0CE0C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {136EAD07-A501-4308-9972-82E44F655735}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {136EAD07-A501-4308-9972-82E44F655735}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {136EAD07-A501-4308-9972-82E44F655735}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {136EAD07-A501-4308-9972-82E44F655735}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -296,6 +302,7 @@ Global
{82580A47-9DBC-43E8-B581-0C35147B4FAD} = {B5E677CF-2920-4B0A-A056-E73F6B2CF2BC}
{B1EF3295-4BF0-489F-8063-C9E3DAE20AA9} = {844CEACD-4C85-4B15-9E2B-892B01FDA4BB}
{4E3BA76C-2A30-4CAD-9F6C-08DF5DF0CE0C} = {B5E677CF-2920-4B0A-A056-E73F6B2CF2BC}
+ {136EAD07-A501-4308-9972-82E44F655735} = {844CEACD-4C85-4B15-9E2B-892B01FDA4BB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {94C0DA2C-CCCB-4314-93A2-9809B5DD0583}
diff --git a/src/SkyApm.Agent.Hosting/Extensions/ServiceCollectionExtensions.cs b/src/SkyApm.Agent.Hosting/Extensions/ServiceCollectionExtensions.cs
index 9d41f14e..ba505d53 100644
--- a/src/SkyApm.Agent.Hosting/Extensions/ServiceCollectionExtensions.cs
+++ b/src/SkyApm.Agent.Hosting/Extensions/ServiceCollectionExtensions.cs
@@ -24,7 +24,6 @@
using SkyApm.Diagnostics.Grpc.Net.Client;
using SkyApm.Diagnostics.HttpClient;
using SkyApm.Diagnostics.SqlClient;
-using SkyApm.Logging;
using SkyApm.Sampling;
using SkyApm.Service;
using SkyApm.Tracing;
@@ -34,8 +33,12 @@
using SkyApm.Utilities.DependencyInjection;
using SkyApm.Utilities.Logging;
using System;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+using Microsoft.Extensions.Logging;
using SkyApm;
using SkyApm.Agent.Hosting;
+using SkyApm.Diagnostics.MSLogging;
+using ILoggerFactory = SkyApm.Logging.ILoggerFactory;
namespace Microsoft.Extensions.DependencyInjection
{
@@ -102,6 +105,7 @@ public static IServiceCollection AddSkyApmLogger(this IServiceCollection service
{
services.AddSingleton();
services.AddSingleton();
+ services.TryAddEnumerable(ServiceDescriptor.Singleton());
return services;
}
diff --git a/src/SkyApm.Agent.Hosting/SkyApm.Agent.Hosting.csproj b/src/SkyApm.Agent.Hosting/SkyApm.Agent.Hosting.csproj
index 4c9fbe5f..8ef772d6 100644
--- a/src/SkyApm.Agent.Hosting/SkyApm.Agent.Hosting.csproj
+++ b/src/SkyApm.Agent.Hosting/SkyApm.Agent.Hosting.csproj
@@ -1,5 +1,5 @@
-
+
$(Product) ASP.NET Core Agent.
$(PackagePrefix).Agent.Hosting
@@ -12,28 +12,29 @@
netcoreapp3.1;net5.0;net6.0
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/SkyApm.Diagnostics.Logging/SkyApmLoggerExtensions.cs b/src/SkyApm.Diagnostics.Logging/SkyApmLoggerExtensions.cs
deleted file mode 100644
index 38fc37c3..00000000
--- a/src/SkyApm.Diagnostics.Logging/SkyApmLoggerExtensions.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Microsoft.Extensions.DependencyInjection.Extensions;
-using Microsoft.Extensions.Logging;
-using SkyApm.Diagnostics.Logging;
-
-namespace Microsoft.Extensions.DependencyInjection
-{
- public static class SkyApmLoggerExtensions
- {
- public static IServiceCollection AddSkyApmLogger(this IServiceCollection service)
- {
- service.TryAddEnumerable(ServiceDescriptor.Singleton());
- return service;
- }
- }
-}
-
diff --git a/src/SkyApm.Diagnostics.Logging/SkyApm.Diagnostics.Logging.csproj b/src/SkyApm.Diagnostics.MSLogging/SkyApm.Diagnostics.MSLogging.csproj
similarity index 89%
rename from src/SkyApm.Diagnostics.Logging/SkyApm.Diagnostics.Logging.csproj
rename to src/SkyApm.Diagnostics.MSLogging/SkyApm.Diagnostics.MSLogging.csproj
index f4f42d79..64186c56 100644
--- a/src/SkyApm.Diagnostics.Logging/SkyApm.Diagnostics.Logging.csproj
+++ b/src/SkyApm.Diagnostics.MSLogging/SkyApm.Diagnostics.MSLogging.csproj
@@ -3,6 +3,7 @@
netcoreapp3.1;net5.0;net6.0
enable
+ SkyApm.Diagnostics.Logging
diff --git a/src/SkyApm.Diagnostics.Logging/SkyApmLogger.cs b/src/SkyApm.Diagnostics.MSLogging/SkyApmLogger.cs
similarity index 55%
rename from src/SkyApm.Diagnostics.Logging/SkyApmLogger.cs
rename to src/SkyApm.Diagnostics.MSLogging/SkyApmLogger.cs
index 09afb7e9..dda95c65 100644
--- a/src/SkyApm.Diagnostics.Logging/SkyApmLogger.cs
+++ b/src/SkyApm.Diagnostics.MSLogging/SkyApmLogger.cs
@@ -5,13 +5,14 @@
using SkyApm.Tracing.Segments;
using SkyApm.Transport;
-namespace SkyApm.Diagnostics.Logging
+namespace SkyApm.Diagnostics.MSLogging
{
- public class SkyApmLogger:ILogger
+ public class SkyApmLogger : ILogger
{
private readonly string _categoryName;
private readonly ISkyApmLogDispatcher _skyApmLogDispatcher;
private readonly IEntrySegmentContextAccessor _entrySegmentContextAccessor;
+
public SkyApmLogger(string categoryName, ISkyApmLogDispatcher skyApmLogDispatcher, IEntrySegmentContextAccessor entrySegmentContextAccessor)
{
_categoryName = categoryName;
@@ -21,25 +22,21 @@ public SkyApmLogger(string categoryName, ISkyApmLogDispatcher skyApmLogDispatche
public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter)
{
- if (true)
+ var logs = new Dictionary();
+ logs.Add("className", _categoryName);
+ logs.Add("Level", logLevel);
+ logs.Add("logMessage", state.ToString() ?? "");
+ var logContext = new LoggerContext()
{
- var logs = new Dictionary();
- logs.Add("className", _categoryName);
- logs.Add("Level", logLevel);
- logs.Add("logMessage", state.ToString()??"");
- var logContext = new LoggerContext()
- {
- Logs = logs,
- SegmentContext = _entrySegmentContextAccessor.Context,
- };
- _skyApmLogDispatcher.Dispatch(logContext);
- }
+ Logs = logs,
+ SegmentContext = _entrySegmentContextAccessor.Context,
+ };
+ _skyApmLogDispatcher.Dispatch(logContext);
}
- public bool IsEnabled(LogLevel logLevel)=>true;
-
+ public bool IsEnabled(LogLevel logLevel) => true;
- public IDisposable BeginScope(TState state)=> default!;
- }
-}
+ public IDisposable BeginScope(TState state) => default!;
+ }
+}
\ No newline at end of file
diff --git a/src/SkyApm.Diagnostics.Logging/SkyApmLoggerProvider.cs b/src/SkyApm.Diagnostics.MSLogging/SkyApmLoggerProvider.cs
similarity index 96%
rename from src/SkyApm.Diagnostics.Logging/SkyApmLoggerProvider.cs
rename to src/SkyApm.Diagnostics.MSLogging/SkyApmLoggerProvider.cs
index b999f2a7..eabb5afc 100644
--- a/src/SkyApm.Diagnostics.Logging/SkyApmLoggerProvider.cs
+++ b/src/SkyApm.Diagnostics.MSLogging/SkyApmLoggerProvider.cs
@@ -3,7 +3,7 @@
using SkyApm.Tracing;
using SkyApm.Transport;
-namespace SkyApm.Diagnostics.Logging
+namespace SkyApm.Diagnostics.MSLogging
{
public class SkyApmLoggerProvider: ILoggerProvider
{
From aaa0d01c1ebe155593f67428f02406e819c33e5b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E6=B3=BD=E5=A8=81?= <1585955375@qq.com>
Date: Sun, 4 Sep 2022 09:38:46 +0800
Subject: [PATCH 3/3] =?UTF-8?q?feat=20:=20=E9=80=82=E9=85=8D=E4=B8=8D?=
=?UTF-8?q?=E9=80=9A=E7=9A=84.net=20=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../SkyApm.Diagnostics.MSLogging.csproj | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/SkyApm.Diagnostics.MSLogging/SkyApm.Diagnostics.MSLogging.csproj b/src/SkyApm.Diagnostics.MSLogging/SkyApm.Diagnostics.MSLogging.csproj
index 64186c56..cfa6c832 100644
--- a/src/SkyApm.Diagnostics.MSLogging/SkyApm.Diagnostics.MSLogging.csproj
+++ b/src/SkyApm.Diagnostics.MSLogging/SkyApm.Diagnostics.MSLogging.csproj
@@ -2,14 +2,22 @@
netcoreapp3.1;net5.0;net6.0
- enable
- SkyApm.Diagnostics.Logging
+ SkyApm.Diagnostics.MSLogging
-
-
+
+
+
+
+
+
+
+
+
+
+
-
+