diff --git a/sample/Sky.Apm.Sample.Logging/Controllers/WeatherForecastController.cs b/sample/Sky.Apm.Sample.Logging/Controllers/WeatherForecastController.cs deleted file mode 100644 index 7db6ab19..00000000 --- a/sample/Sky.Apm.Sample.Logging/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the SkyAPM under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The SkyAPM licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -using Microsoft.AspNetCore.Mvc; -using SkyApm.Diagnostics.Logging; -using SkyApm.Tracing; - -namespace Sky.Apm.Sample.Logging.Controllers -{ - [ApiController] - [Route("apitest")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly Test _test; - private readonly ISkyApmLogger _skyApmLogger; - public WeatherForecastController(ISkyApmLogger skyApmLogger, Test test) - { - _skyApmLogger = skyApmLogger; - _test = test; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - //Console.WriteLine(_entrySegmentContextAccessor.Context?.TraceId); - _skyApmLogger.Information("下订单成功!"); - _test.Create(); - 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/Sky.Apm.Sample.Logging/Program.cs b/sample/Sky.Apm.Sample.Logging/Program.cs deleted file mode 100644 index b1dd1d28..00000000 --- a/sample/Sky.Apm.Sample.Logging/Program.cs +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the SkyAPM under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The SkyAPM licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -using Sky.Apm.Sample.Logging; - -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(); -builder.Services.AddScoped(); -builder.Services.AddPushSkyApmLogger(x => x.Enable = true); -var app = builder.Build(); - -// Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger(); - app.UseSwaggerUI(); -} - -app.UseAuthorization(); - -app.MapControllers(); - -app.Run(); diff --git a/sample/Sky.Apm.Sample.Logging/Properties/launchSettings.json b/sample/Sky.Apm.Sample.Logging/Properties/launchSettings.json deleted file mode 100644 index 48a53e29..00000000 --- a/sample/Sky.Apm.Sample.Logging/Properties/launchSettings.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:2952", - "sslPort": 0 - } - }, - "profiles": { - "Sky.Apm.Sample.Logging": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "http://localhost:5008", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development", - "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "SkyAPM.Agent.AspNetCore" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "swagger", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} diff --git a/sample/Sky.Apm.Sample.Logging/Sky.Apm.Sample.Logging.csproj b/sample/Sky.Apm.Sample.Logging/Sky.Apm.Sample.Logging.csproj deleted file mode 100644 index 92196e0c..00000000 --- a/sample/Sky.Apm.Sample.Logging/Sky.Apm.Sample.Logging.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - - - - - - - - - - diff --git a/sample/Sky.Apm.Sample.Logging/Test.cs b/sample/Sky.Apm.Sample.Logging/Test.cs deleted file mode 100644 index 70f1394d..00000000 --- a/sample/Sky.Apm.Sample.Logging/Test.cs +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the SkyAPM under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The SkyAPM licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -namespace Sky.Apm.Sample.Logging -{ - public class Test - { - private readonly ILogger _logger; - - public Test(ILogger logger) - { - _logger = logger; - } - - public void Create() - { - _logger.LogError("创建了一个用户对象",new List { "asdasdas","3ewqeqdad","q34asdase2qq"}); - } - } -} diff --git a/sample/Sky.Apm.Sample.Logging/WeatherForecast.cs b/sample/Sky.Apm.Sample.Logging/WeatherForecast.cs deleted file mode 100644 index 84dd98e0..00000000 --- a/sample/Sky.Apm.Sample.Logging/WeatherForecast.cs +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the SkyAPM under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The SkyAPM licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -namespace Sky.Apm.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/Sky.Apm.Sample.Logging/appsettings.Development.json b/sample/Sky.Apm.Sample.Logging/appsettings.Development.json deleted file mode 100644 index 0c208ae9..00000000 --- a/sample/Sky.Apm.Sample.Logging/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/sample/Sky.Apm.Sample.Logging/appsettings.json b/sample/Sky.Apm.Sample.Logging/appsettings.json deleted file mode 100644 index 10f68b8c..00000000 --- a/sample/Sky.Apm.Sample.Logging/appsettings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*" -} diff --git a/sample/Sky.Apm.Sample.Logging/skyapm.json b/sample/Sky.Apm.Sample.Logging/skyapm.json deleted file mode 100644 index bb2eea93..00000000 --- a/sample/Sky.Apm.Sample.Logging/skyapm.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "SkyWalking": { - "ServiceName": "Sky.Apm.Sample.Logging", - "Namespace": "", - "HeaderVersions": [ - "sw8" - ], - "Sampling": { - "SamplePer3Secs": -1, - "Percentage": -1.0 - }, - "Logging": { - "Level": "Information", - "FilePath": "logs\\skyapm-{Date}.log" - }, - "Transport": { - "Interval": 3000, - "ProtocolVersion": "v8", - "QueueSize": 30000, - "BatchSize": 3000, - "gRPC": { - "Servers": "101.34.26.221:40009", - "Timeout": 10000, - "ConnectTimeout": 10000, - "ReportTimeout": 600000 //, - //"Authentication": "" - } - } - } -} \ No newline at end of file diff --git a/skyapm-dotnet.sln b/skyapm-dotnet.sln index e0d49b9f..aac867d6 100644 --- a/skyapm-dotnet.sln +++ b/skyapm-dotnet.sln @@ -109,10 +109,6 @@ 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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sky.Apm.Sample.Logging", "sample\Sky.Apm.Sample.Logging\Sky.Apm.Sample.Logging.csproj", "{D35905EC-EB46-4A3D-BD2B-02C4C868BC65}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkyApm.Diagnostics.Logging", "src\SkyApm.Diagnostics.Logging\SkyApm.Diagnostics.Logging.csproj", "{DDF18F43-E1D2-4854-AC97-DFC321EF6563}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -247,14 +243,6 @@ 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 - {D35905EC-EB46-4A3D-BD2B-02C4C868BC65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D35905EC-EB46-4A3D-BD2B-02C4C868BC65}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D35905EC-EB46-4A3D-BD2B-02C4C868BC65}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D35905EC-EB46-4A3D-BD2B-02C4C868BC65}.Release|Any CPU.Build.0 = Release|Any CPU - {DDF18F43-E1D2-4854-AC97-DFC321EF6563}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DDF18F43-E1D2-4854-AC97-DFC321EF6563}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DDF18F43-E1D2-4854-AC97-DFC321EF6563}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DDF18F43-E1D2-4854-AC97-DFC321EF6563}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -301,8 +289,6 @@ 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} - {D35905EC-EB46-4A3D-BD2B-02C4C868BC65} = {844CEACD-4C85-4B15-9E2B-892B01FDA4BB} - {DDF18F43-E1D2-4854-AC97-DFC321EF6563} = {B5E677CF-2920-4B0A-A056-E73F6B2CF2BC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {94C0DA2C-CCCB-4314-93A2-9809B5DD0583} diff --git a/src/SkyApm.Core/Service/PingService.cs b/src/SkyApm.Core/Service/PingService.cs index 00cf419c..23b3d9f8 100644 --- a/src/SkyApm.Core/Service/PingService.cs +++ b/src/SkyApm.Core/Service/PingService.cs @@ -51,7 +51,7 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken) await _pingCaller.PingAsync( new PingRequest { - ServiceName = _instrumentConfig.ServiceName ?? _instrumentConfig.ApplicationCode, + ServiceName = _instrumentConfig.ServiceName, InstanceId = _instrumentConfig.ServiceInstanceName }, cancellationToken); Logger.Information($"Ping server @{DateTimeOffset.UtcNow}"); diff --git a/src/SkyApm.Core/Service/RegisterService.cs b/src/SkyApm.Core/Service/RegisterService.cs index 04ef5884..7d7dd457 100644 --- a/src/SkyApm.Core/Service/RegisterService.cs +++ b/src/SkyApm.Core/Service/RegisterService.cs @@ -65,7 +65,7 @@ private async Task ReportServiceInstancePropertiesAsync(CancellationToken cancel }; var request = new ServiceInstancePropertiesRequest { - ServiceId = _config.ServiceName ?? _config.ApplicationCode, + ServiceId = _config.ServiceName, ServiceInstanceId = _config.ServiceInstanceName, Properties = properties }; diff --git a/src/SkyApm.Core/Tracing/SegmentContextFactory.cs b/src/SkyApm.Core/Tracing/SegmentContextFactory.cs index 8430bf39..dd10f3b4 100644 --- a/src/SkyApm.Core/Tracing/SegmentContextFactory.cs +++ b/src/SkyApm.Core/Tracing/SegmentContextFactory.cs @@ -57,7 +57,7 @@ public SegmentContext CreateEntrySegment(string operationName, ICarrier carrier, var segmentId = GetSegmentId(); var sampled = GetSampled(carrier, operationName); var segmentContext = new SegmentContext(traceId, segmentId, sampled, - _instrumentConfig.ServiceName ?? _instrumentConfig.ApplicationCode, + _instrumentConfig.ServiceName, _instrumentConfig.ServiceInstanceName, operationName, SpanType.Entry, startTimeMilliseconds); @@ -90,7 +90,7 @@ public SegmentContext CreateLocalSegment(string operationName, long startTimeMil var segmentId = GetSegmentId(); var sampled = GetSampled(parentSegmentContext, operationName); var segmentContext = new SegmentContext(traceId, segmentId, sampled, - _instrumentConfig.ServiceName ?? _instrumentConfig.ApplicationCode, + _instrumentConfig.ServiceName, _instrumentConfig.ServiceInstanceName, operationName, SpanType.Local, startTimeMilliseconds); @@ -125,7 +125,7 @@ public SegmentContext CreateExitSegment(string operationName, StringOrIntValue n var segmentId = GetSegmentId(); var sampled = GetSampled(parentSegmentContext, operationName, networkAddress); var segmentContext = new SegmentContext(traceId, segmentId, sampled, - _instrumentConfig.ServiceName ?? _instrumentConfig.ApplicationCode, + _instrumentConfig.ServiceName, _instrumentConfig.ServiceInstanceName, operationName, SpanType.Exit, startTimeMilliseconds); diff --git a/src/SkyApm.Diagnostics.Logging/ISkyApmLogger.cs b/src/SkyApm.Diagnostics.Logging/ISkyApmLogger.cs deleted file mode 100644 index e429eb5c..00000000 --- a/src/SkyApm.Diagnostics.Logging/ISkyApmLogger.cs +++ /dev/null @@ -1,11 +0,0 @@ -using SkyApm.Logging; - -namespace SkyApm.Diagnostics.Logging -{ - public interface ISkyApmLogger :ILogger - { - - - - } -} \ No newline at end of file diff --git a/src/SkyApm.Diagnostics.Logging/ServiceCollectionExtensions.cs b/src/SkyApm.Diagnostics.Logging/ServiceCollectionExtensions.cs deleted file mode 100644 index 097bec0f..00000000 --- a/src/SkyApm.Diagnostics.Logging/ServiceCollectionExtensions.cs +++ /dev/null @@ -1,28 +0,0 @@ -using SkyApm.Config; -using SkyApm.Diagnostics.Logging; -using System; - -namespace Microsoft.Extensions.DependencyInjection -{ - public static class ServiceCollectionExtensions - { - - public static IServiceCollection AddPushSkyApmLogger(this IServiceCollection services, Action action) - { - if (services == null) - { - throw new ArgumentNullException(nameof(services)); - } - if (action == null) - { - throw new ArgumentNullException(nameof(action)); - } - LogPushSkywalkingConfig logPushSkywalking = new LogPushSkywalkingConfig(); - action.Invoke(logPushSkywalking); - services.Configure(action); - - services.Add(new ServiceDescriptor(typeof(ISkyApmLogger<>), typeof(SkyApmLogger<>), ServiceLifetime.Singleton)); - return services; - } - } -} diff --git a/src/SkyApm.Diagnostics.Logging/SkyApm.Diagnostics.Logging.csproj b/src/SkyApm.Diagnostics.Logging/SkyApm.Diagnostics.Logging.csproj deleted file mode 100644 index bd690118..00000000 --- a/src/SkyApm.Diagnostics.Logging/SkyApm.Diagnostics.Logging.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - netcoreapp3.1;net5.0;net6.0 - enable - - - - - - - - - - - diff --git a/src/SkyApm.Diagnostics.Logging/SkyApmLogger.cs b/src/SkyApm.Diagnostics.Logging/SkyApmLogger.cs deleted file mode 100644 index 34205e9f..00000000 --- a/src/SkyApm.Diagnostics.Logging/SkyApmLogger.cs +++ /dev/null @@ -1,81 +0,0 @@ -using Microsoft.Extensions.Options; -using SkyApm.Config; -using SkyApm.Logging; -using SkyApm.Tracing; -using SkyApm.Tracing.Segments; -using SkyApm.Transport; -using System; -using System.Collections.Generic; - -namespace SkyApm.Diagnostics.Logging -{ - - public class SkyApmLogger : ISkyApmLogger - { - - private readonly bool _pushSkywalking; - private readonly Type _loggerName; - private readonly IEntrySegmentContextAccessor _entrySegmentContextAccessor; - private readonly ISkyApmLogDispatcher _skyApmLogDispatcher; - public SkyApmLogger(IEntrySegmentContextAccessor entrySegmentContextAccessor, ISkyApmLogDispatcher skyApmLogDispatcher, IOptions logPushSkywalkingConfig) - { - _loggerName = typeof(TCategoryName); - _entrySegmentContextAccessor = entrySegmentContextAccessor; - _skyApmLogDispatcher = skyApmLogDispatcher; - _pushSkywalking = logPushSkywalkingConfig.Value.Enable; - } - - public void Debug(string message) - { - SendLog("Debug", message); - } - - public void Error(string message, Exception exception) - { - SendLog("Error", message); - } - - public void Information(string message) - { - SendLog("Information", message); - } - - public void Trace(string message) - { - SendLog("Trace", message); - } - - public void Warning(string message) - { - SendLog("Warning", message); - } - - private void SendLog(string logLevel, string message) - { - if (_pushSkywalking) - { - var logs = new Dictionary(); - logs.Add("className", _loggerName); - logs.Add("Level", logLevel); - logs.Add("logMessage", message); - var logContext = new LoggerContext() - { - Logs = logs, - SegmentContext = _entrySegmentContextAccessor.Context, - Date = DateTimeOffset.UtcNow.Offset.Ticks - }; - _skyApmLogDispatcher.Dispatch(logContext); - } - - } - - } - - //public class SkyApmLoggerFactory : ILoggerFactory - //{ - // public ILogger CreateLogger(Type type) - // { - // throw new NotImplementedException(); - // } - //} -} \ No newline at end of file diff --git a/src/SkyApm.Transport.Grpc/V8/CLRStatsReporter.cs b/src/SkyApm.Transport.Grpc/V8/CLRStatsReporter.cs index 9c9f3ab5..fff86a0e 100644 --- a/src/SkyApm.Transport.Grpc/V8/CLRStatsReporter.cs +++ b/src/SkyApm.Transport.Grpc/V8/CLRStatsReporter.cs @@ -57,7 +57,7 @@ public async Task ReportAsync(CLRStatsRequest statsRequest, { var request = new CLRMetricCollection { - Service = _instrumentConfig.ServiceName ?? _instrumentConfig.ApplicationCode, + Service = _instrumentConfig.ServiceName, ServiceInstance = _instrumentConfig.ServiceInstanceName, }; var metric = new CLRMetric diff --git a/src/SkyApm.Utilities.Logging/DefaultLoggerFactory.cs b/src/SkyApm.Utilities.Logging/DefaultLoggerFactory.cs index e2f3e827..598649fd 100644 --- a/src/SkyApm.Utilities.Logging/DefaultLoggerFactory.cs +++ b/src/SkyApm.Utilities.Logging/DefaultLoggerFactory.cs @@ -46,7 +46,7 @@ public DefaultLoggerFactory(IConfigAccessor configAccessor) _loggerFactory.AddSerilog(new LoggerConfiguration().MinimumLevel.Verbose().Enrich .WithProperty("SourceContext", null).Enrich .WithProperty(nameof(instrumentationConfig.ServiceName), - instrumentationConfig.ServiceName ?? instrumentationConfig.ApplicationCode).Enrich + instrumentationConfig.ServiceName).Enrich .FromLogContext().WriteTo.RollingFile(_loggingConfig.FilePath, level, outputTemplate, null, 1073741824, 31, null, false, false, TimeSpan.FromMilliseconds(500)).CreateLogger()); } diff --git a/src/SkyApm.Utilities.Logging/SkyApmLogger.cs b/src/SkyApm.Utilities.Logging/SkyApmLogger.cs deleted file mode 100644 index 432b59bd..00000000 --- a/src/SkyApm.Utilities.Logging/SkyApmLogger.cs +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the SkyAPM under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The SkyAPM licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -using Microsoft.Extensions.DependencyInjection; -using SkyApm.Logging; -using SkyApm.Tracing; -using SkyApm.Tracing.Segments; -using SkyApm.Transport; -using System; -using System.Collections.Generic; - -namespace SkyApm.Utilities.Logging -{ - public class SkyApmLogger : ILogger - { - private readonly Type _loggerName; - private readonly IEntrySegmentContextAccessor _entrySegmentContextAccessor; - private readonly ISkyApmLogDispatcher _skyApmLogDispatcher; - private readonly bool _pushSkywalking; - public SkyApmLogger(Type type, IServiceProvider serviceProvider,bool pushSkywalking) - { - _entrySegmentContextAccessor = serviceProvider.GetService(); - _skyApmLogDispatcher = serviceProvider.GetService(); - _loggerName = type; - _pushSkywalking= pushSkywalking; - } - - public void Debug(string message) - { - SendLog("Debug", message); - } - - public void Error(string message, Exception exception) - { - SendLog("Error", message); - } - - public void Information(string message) - { - SendLog("Information", message); - } - - public void Trace(string message) - { - SendLog("Trace", message); - } - - public void Warning(string message) - { - SendLog("Warning", message); - } - - private void SendLog(string logLevel, string message) - { - if(_pushSkywalking) - { - var logs = new Dictionary(); - logs.Add("className", _loggerName); - logs.Add("Level", logLevel); - logs.Add("logMessage", message); - var logContext = new LoggerContext() - { - Logs = logs, - SegmentContext = _entrySegmentContextAccessor.Context, - }; - _skyApmLogDispatcher.Dispatch(logContext); - } - - } - } -}