Skip to content

Dev #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
14 changes: 14 additions & 0 deletions Space.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Space.ElasticSearch.Tests",
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Redis", "Redis", "{C1FCC0F0-91B1-438F-975E-D2B8797A2A91}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Space.Util", "src\Space.Util\Space.Util.csproj", "{E400A9EE-3C4F-4304-AF3E-9C274BEB0924}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Space.Log4Net.Jaeger", "src\Space.Log4Net.Jaeger\Space.Log4Net.Jaeger.csproj", "{1FB4FC51-D33A-4F5E-8C09-9D6637D541B3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -118,6 +122,14 @@ Global
{B8A47991-2442-42D5-8479-F4D7B56980A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8A47991-2442-42D5-8479-F4D7B56980A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8A47991-2442-42D5-8479-F4D7B56980A3}.Release|Any CPU.Build.0 = Release|Any CPU
{E400A9EE-3C4F-4304-AF3E-9C274BEB0924}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E400A9EE-3C4F-4304-AF3E-9C274BEB0924}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E400A9EE-3C4F-4304-AF3E-9C274BEB0924}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E400A9EE-3C4F-4304-AF3E-9C274BEB0924}.Release|Any CPU.Build.0 = Release|Any CPU
{1FB4FC51-D33A-4F5E-8C09-9D6637D541B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FB4FC51-D33A-4F5E-8C09-9D6637D541B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FB4FC51-D33A-4F5E-8C09-9D6637D541B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FB4FC51-D33A-4F5E-8C09-9D6637D541B3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -142,6 +154,8 @@ Global
{D71E7280-0218-4C15-88D1-FD1DB39BD4B2} = {77B3A402-B14B-43B4-BE28-43BC348F3979}
{B8A47991-2442-42D5-8479-F4D7B56980A3} = {4ABDAB5E-8B75-4EC3-8782-C90CF802A0E5}
{C1FCC0F0-91B1-438F-975E-D2B8797A2A91} = {77B3A402-B14B-43B4-BE28-43BC348F3979}
{E400A9EE-3C4F-4304-AF3E-9C274BEB0924} = {77B3A402-B14B-43B4-BE28-43BC348F3979}
{1FB4FC51-D33A-4F5E-8C09-9D6637D541B3} = {77B3A402-B14B-43B4-BE28-43BC348F3979}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DD8BCF2C-FF99-4972-80B1-D7C1D9623CD1}
Expand Down
6 changes: 5 additions & 1 deletion build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<MicrosoftExtensionsOptionsConfigurationExtensions>2.2.0</MicrosoftExtensionsOptionsConfigurationExtensions>
<MicrosoftAspNetCoreHostingServerAbstractions>2.2.0</MicrosoftAspNetCoreHostingServerAbstractions>
<MicrosoftAspNetCoreHostingAbstractions>2.2.0</MicrosoftAspNetCoreHostingAbstractions>
<EPPlus>4.5.3</EPPlus>
<MicrosoftAspNetCoreMvcCore>2.2.0</MicrosoftAspNetCoreMvcCore>
<OpenTracingContribNetCore>0.6.2</OpenTracingContribNetCore>
<Jaeger>0.3.7</Jaeger>
</PropertyGroup>

<PropertyGroup Label="Package information">
Expand All @@ -44,7 +48,7 @@
<IncludeSymbols>True</IncludeSymbols>
<LangVersion>latest</LangVersion>
<NoWarn>1591</NoWarn>
<RepositoryUrl>https://gitee.com/winxeos/NetCoreSample</RepositoryUrl>
<RepositoryUrl>https://github.com/scapex/NetCore_SDK</RepositoryUrl>
<PackageProjectUrl>$(RepositoryUrl)/src/$(MSBuildProjectName)</PackageProjectUrl>
<RepositoryType>Git</RepositoryType>
<PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign>
Expand Down
13 changes: 6 additions & 7 deletions src/Space.Consul/ConsulExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Linq;
using Consul;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -37,9 +34,11 @@ public static IApplicationBuilder UseConsul(this IApplicationBuilder app)
var loggerFactory = app.ApplicationServices.GetRequiredService<ILoggerFactory>();
var logger = loggerFactory.CreateLogger<IApplicationBuilder>();

var features = app.Properties["server.Features"] as FeatureCollection;
var addresses = features?.Get<IServerAddressesFeature>();
var address = addresses?.Addresses.First();
/* var features = app.Properties["server.Features"] as FeatureCollection;
var addresses = features?.Get<IServerAddressesFeature>();
var address = addresses?.Addresses.First();*/

var address = Util.GetEndPoint();

var uri = new Uri(address);
var registration = new AgentServiceRegistration()
Expand All @@ -52,7 +51,7 @@ public static IApplicationBuilder UseConsul(this IApplicationBuilder app)
TCP = $"{uri.Host}:{uri.Port}"
},
ID = $"{consulConfig.Id ?? Guid.NewGuid()}-{uri.Port}",
Name = consulConfig.Name ?? AppDomain.CurrentDomain.FriendlyName.Replace(".",""),
Name = consulConfig.Name ?? AppDomain.CurrentDomain.FriendlyName.Replace(".", ""),
Address = uri.Host,
Port = uri.Port,
Tags = consulConfig.Tags,
Expand Down
2 changes: 1 addition & 1 deletion src/Space.DnsClient/DnsEndpointOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ internal class DnsEndpointOptions
/// Consul服务端口
/// </summary>
public int Port { get; set; }
public IPEndPoint GetIpEndPoint() => new IPEndPoint(IPAddress.Parse(Address), Port);
public IPEndPoint GetIpEndPoint() => new(IPAddress.Parse(Address), Port);
}
}
86 changes: 86 additions & 0 deletions src/Space.Log4Net.Jaeger/Build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
@echo off
for /f "tokens=2*" %%i in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion^|findstr "ProgramFilesDir (x86)"') do set p=%%j

set a=%cd: =:%
set a=%a:\= %
for %%j in (%a%) do (set a=%%j)
set a=%a::= %

set defaultProgramDir=C:\Program Files (x86)
set driList[0]=%p:~10%
if "%driList[0]%" NEQ "%defaultProgramDir%" set driList[1]=%defaultProgramDir%

set buildList[0]=Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin
set buildList[1]=Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin
set buildList[2]=Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin
set buildList[3]=MSBuild\14.0\Bin
set buildList[4]=MSBuild\12.0\Bin
set buildList[5]=MSBuild\11.0\Bin
set buildList[6]=MSBuild\10.0\Bin

for /F "tokens=2 delims==" %%d in ('set driList[') do (
for /F "tokens=2 delims==" %%b in ('set buildList[') do (
set MSBuild="%%d\%%b\MSBuild.exe"
if exist "%%d\%%b\MSBuild.exe" (
GOTO SetMSBuild
)
)
)

set MSBuild=%windir%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe

:SetMSBuild
set Nuget=nuget restore

if exist "%a%.csproj" (
set MSBuild=%MSBuild% "%a%.csproj"
set Nuget=%Nuget% "%a%.csproj"
) else if exist "%a%.vbproj" (
set MSBuild=%MSBuild% "%a%.vbproj"
set Nuget=%Nuget% "%a%.vbproj"
) else if exist "%a%.sln" (
set MSBuild=%MSBuild% "%a%.sln"
set Nuget=%Nuget% "%a%.sln"
)

if "%1" == "Debug" (
set MSBuild=%MSBuild% /m /v:m /p:Configuration=Debug
) else (
set MSBuild=%MSBuild% /m /v:m /p:Configuration=Release
)

if exist "nuget.exe" (
echo nuget source add -name tencent.com -source https://mirrors.cloud.tencent.com/nuget
nuget source add -name tencent.com -source https://mirrors.cloud.tencent.com/nuget
echo.

echo %Nuget%
%Nuget%
echo.

echo %MSBuild%
%MSBuild%

:: IF %ERRORLEVEL% EQU 0 (
IF ERRORLEVEL 0 (
if exist "%a%.csproj" (
if not exist "%a%.nuspec" (
nuget spec
)

echo.
nuget pack "%a%.csproj" -Prop Configuration=Release
) else if exist "%a%.vbproj" (
if not exist "%a%.nuspec" (
nuget spec
)

echo.
nuget pack "%a%.vbproj" -Prop Configuration=Release
)
)
) else (
echo %MSBuild%
%MSBuild%
)
pause
81 changes: 81 additions & 0 deletions src/Space.Log4Net.Jaeger/Log4NetExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using Jaeger;
using Jaeger.Propagation;
using Jaeger.Samplers;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OpenTracing;
using OpenTracing.Contrib.NetCore.Internal;
using OpenTracing.Propagation;
using OpenTracing.Util;

namespace Space.Log4Net
{
public static class Log4NetExtensions
{
public static IServiceCollection AddLog4Net(this IServiceCollection services, string serviceName)
{
services.AddOpenTracing();

//https://www.alibabacloud.com/help/zh/doc-detail/99880.htm#title-wdi-s6z-hrq
// 过滤httpclient采集中的Jaeger数据上报请求。
//var httpOption = new HttpHandlerDiagnosticOptions();
//httpOption.IgnorePatterns.Add(req => req.RequestUri.AbsolutePath.Contains("/api/traces"));
//services.AddSingleton(Options.Create(httpOption));

// Adds the Jaeger Tracer.
services.AddSingleton<ITracer>(serviceProvider =>
{

var loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
//var senderConfiguration = new Configuration.SenderConfiguration(loggerFactory)
// // 在链路追踪控制台获取Jaeger Endpoint。
// .WithEndpoint("http://tracing-analysis-dc-sz.aliyuncs.com/adapt_your_token/api/traces");


// This will log to a default localhost installation of Jaeger.
var tracer = new Tracer.Builder(serviceName)
.WithLoggerFactory(loggerFactory)
.WithSampler(new ConstSampler(true))
//.WithReporter(new RemoteReporter.Builder().WithFlushInterval(TimeSpan.FromSeconds(3)).WithSender(senderConfiguration.GetSender()).Build())
.RegisterCodec(BuiltinFormats.HttpHeaders, new TextMapCodec(true))
.RegisterCodec(BuiltinFormats.TextMap, new TextMapCodec(false))
.Build();

// Allows code that can't use DI to also access the tracer.
GlobalTracer.Register(tracer);

return tracer;
});

return services;
}

internal static ILoggerFactory AddLog4Net([NotNull] this ILoggerFactory loggerFactory, string log4NetConfigFile, IGlobalTracerAccessor globalTracerAccessor, string environmentName)
{
if (!File.Exists(log4NetConfigFile))
throw new ValidationException($"{nameof(log4NetConfigFile)} path not exists");

loggerFactory.AddProvider(new Log4NetProvider(log4NetConfigFile, globalTracerAccessor, environmentName));
return loggerFactory;
}

public static IApplicationBuilder UseLog4Net([NotNull] this IApplicationBuilder app, string environmentName) => UseLog4Net(app, "log4net.config", environmentName);

public static IApplicationBuilder UseLog4Net([NotNull] this IApplicationBuilder app, [NotNull] string log4NetConfigFile, string environmentName)
{
if (app == null) throw new ArgumentNullException(nameof(app));
if (log4NetConfigFile == null) throw new ArgumentNullException(nameof(log4NetConfigFile));

var globalTracerAccessor = app.ApplicationServices.GetRequiredService<IGlobalTracerAccessor>();

app.ApplicationServices.GetRequiredService<ILoggerFactory>().AddLog4Net(log4NetConfigFile, globalTracerAccessor, environmentName);

return app;
}
}
}
Loading