Skip to content

Commit

Permalink
1.2.0.56
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvees committed Apr 25, 2018
1 parent 16d4dbe commit c299315
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 26 deletions.
9 changes: 5 additions & 4 deletions src/Agent.Cocohub/Agent.Cocohub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0.0.15</Version>
<FileVersion>1.0.0.15</FileVersion>
<AssemblyVersion>1.0.0.15</AssemblyVersion>
<Version>1.0.0.19</Version>
<FileVersion>1.0.0.19</FileVersion>
<AssemblyVersion>1.0.0.19</AssemblyVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="Microsoft.CSharp" Version="4.4.1" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 11 additions & 2 deletions src/Agent.Cocohub/AgentThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,28 @@ internal static void CoreWrite()
continue;
}
List<LogEntity> entities = new List<LogEntity>();
List<string> _error = new List<string>();
for (int i = 0; i < loop; i++)
{
if (_logs.TryDequeue(out var log) && !string.IsNullOrEmpty(log))
{
if (LogResolver.TryResolve(log, out var entity) && entity != null)
entities.Add(entity);
else
Console.WriteLine("TryResolve error:" + log);
{
_error.Add(log);
}
}
else
Console.WriteLine("Dequeue error.");
}

if (_error.Count >= 0)
{
File.AppendAllLines("_resolve.err.nut", _error);
_error.Clear();
_error = null;
}

if (entities.Count > 0)
_write(entities);

Expand Down
20 changes: 12 additions & 8 deletions src/Agent.Cocohub/Log/LogResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@ public static bool TryResolve(string log, out LogEntity entity)
if (string.IsNullOrEmpty(log))
return false;

var parts = log.Split(new string[] { "] " }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length != 3)
return false;
//here is a sample data
//[2018-04-10 20:43:30.419] [Info] {"Action":"Return","Method":"System.String[] LifeVC.Biz.OrderLogic.OrdersBiz::GetRegion(System.Int32)","Result":"$return=System.String[]","Time":25,"TracerId":"718f1d9f02054b40a68ce241f4fa98e310643936","SpanId":"0.2.1.3"}
string[] parts = new string[3];
parts[0] = log.Substring(1, 23).Trim(); //2018-04-10 20:43:30.419
string sub = log.Substring(27);
parts[1] = sub.Substring(0, sub.IndexOf("]")).Trim(); //Info
parts[2] = log.Substring(log.IndexOf("{")).Trim(); //{json}

try
{
entity = DynamicJson.Deserialize<LogEntity>(parts[2].Trim());
entity = DynamicJson.Deserialize<LogEntity>(parts[2]);

entity.LogTime = DateTime.Parse(parts[0].Trim().Replace("[", string.Empty).Replace("]", string.Empty));
entity.LogTime = DateTime.Parse(parts[0]);

entity.Level = parts[1].Trim().Replace("[", string.Empty).Replace("]", string.Empty);
entity.Level = parts[1];

entity.HasException = parts[2].ToLower().Contains("exception");
entity.HasException = parts[2].Contains("$exception");
}
catch
catch(Exception ex)
{
entity = null;
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/ApiSample/ApiSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Cocohub.Tracer.Fody" Version="2.0.0.32" />
<PackageReference Include="Cocohub.Tracer.Fody" Version="2.0.0.52" />
<PackageReference Include="Fody" Version="2.3.20" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Remote.Cocohub" Version="1.0.0" />
<PackageReference Include="Tracer.Cocohub" Version="1.2.0.32" />
<PackageReference Include="Tracer.Cocohub" Version="1.2.0.55" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 7 additions & 1 deletion src/CocoHub.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cocohub.Tracer", "Cocohub.T
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MultiTree.Cocohub", "MultiTree.Cocohub\MultiTree.Cocohub.csproj", "{587201C3-2F5B-457B-BD38-45066EB4D6E9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Agent.Cocohub", "Agent.Cocohub\Agent.Cocohub.csproj", "{3B54902E-C594-42F7-A645-41823E22FDB8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Agent.Cocohub", "Agent.Cocohub\Agent.Cocohub.csproj", "{3B54902E-C594-42F7-A645-41823E22FDB8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTest", "UnitTest\UnitTest.csproj", "{31995922-E6E4-49BE-9B50-BE36913C7130}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -69,6 +71,10 @@ Global
{3B54902E-C594-42F7-A645-41823E22FDB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B54902E-C594-42F7-A645-41823E22FDB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B54902E-C594-42F7-A645-41823E22FDB8}.Release|Any CPU.Build.0 = Release|Any CPU
{31995922-E6E4-49BE-9B50-BE36913C7130}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31995922-E6E4-49BE-9B50-BE36913C7130}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31995922-E6E4-49BE-9B50-BE36913C7130}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31995922-E6E4-49BE-9B50-BE36913C7130}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions src/LibSample/LibSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cocohub.Tracer.Fody" Version="2.0.0.24" />
<PackageReference Include="Cocohub.Tracer.Fody" Version="2.0.0.52" />
<PackageReference Include="Fody" Version="2.3.20" />
<PackageReference Include="Tracer.Cocohub" Version="1.2.0.24" />
<PackageReference Include="Tracer.Cocohub" Version="1.2.0.55" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/Remote.Cocohub/Http/RequestAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void Send(HttpMethod method, Uri uri, HttpContent body, Action<Htt
catch (Exception ex)
{
sw.Stop();
string logEx = string.Format(_exception, ex.Message + ex.StackTrace);
string logEx = string.Format(_exception, ex.Message.Replace(@"\", @"\\") + ex.StackTrace.Replace(@"\", @"\\"));
string logEnter = string.Format(_textEnterWithTracer, "Http" + method.Method, uri.ToString(), TracerContext.Tracer.TracerId, TracerContext.Tracer.SpanId);
string logReturn = string.Format(_textReturnWithTracer, "Http" + method.Method, logEx, sw.ElapsedMilliseconds, TracerContext.Tracer.TracerId, TracerContext.Tracer.SpanId);

Expand Down Expand Up @@ -109,7 +109,7 @@ public static async void SendAsync(HttpMethod method, Uri uri, HttpContent body,
{
sw.Stop();
var tracers = tracer.Split(TracerIndentity.Spliter, StringSplitOptions.RemoveEmptyEntries);
string logEx = string.Format(_exception, ex.Message + ex.StackTrace);
string logEx = string.Format(_exception, ex.Message.Replace(@"\", @"\\") + ex.StackTrace.Replace(@"\", @"\\"));
string logEnter = string.Format(_textEnterWithTracer, "Http" + method.Method, uri.ToString(), tracers[0], tracers[1]);
string logReturn = string.Format(_textReturnWithTracer, "Http" + method.Method, logEx, sw.ElapsedMilliseconds, tracers[0], tracers[1]);

Expand Down
3 changes: 3 additions & 0 deletions src/Remote.Cocohub/Remote.Cocohub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AssemblyVersion>1.0.0.1</AssemblyVersion>
<FileVersion>1.0.0.1</FileVersion>
<Version>1.0.0.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Sample/Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cocohub.Tracer.Fody" Version="2.0.0.24" />
<PackageReference Include="Cocohub.Tracer.Fody" Version="2.0.0.52" />
<PackageReference Include="Fody" Version="2.3.20" />
<PackageReference Include="Tracer.Cocohub" Version="1.2.0.24" />
<PackageReference Include="Tracer.Cocohub" Version="1.2.0.55" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions src/Tracer.Cocohub/Adapters/LoggerAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public void TraceLeave(string methodInfo, long startTicks, long endTicks, string
StringBuilder parameters = new StringBuilder();
for (int i = 0; i < paramNames.Length; i++)
{
if (paramNames[i] == "$exception")
{
var value = paramValues[i].ToString();
paramValues[i] = value;
}
parameters.AppendFormat("{0}={1}", paramNames[i] ?? "$return",
paramValues[i] == null ? NullString : paramValues[i].ToString().Replace("\r\n", string.Empty).Replace("\"", string.Empty));
if (i < paramNames.Length - 1) parameters.Append(", ");
Expand Down
6 changes: 3 additions & 3 deletions src/Tracer.Cocohub/Tracer.Cocohub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<AssemblyName>Tracer.Cocohub</AssemblyName>
<RootNamespace>Tracer.Cocohub</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.2.0.55</Version>
<AssemblyVersion>1.2.0.55</AssemblyVersion>
<FileVersion>1.2.0.55</FileVersion>
<Version>1.2.0.56</Version>
<AssemblyVersion>1.2.0.56</AssemblyVersion>
<FileVersion>1.2.0.56</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
19 changes: 19 additions & 0 deletions src/UnitTest/LogResolverTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Agent.Cocohub.Entity;
using Agent.Cocohub.Log;
using System;
using System.IO;
using Xunit;

namespace UnitTest
{
public class LogResolverTest
{
[Fact]
public void Test()
{
string log = File.ReadAllText("input.txt");
LogEntity entity;
Assert.True(LogResolver.TryResolve(log, out entity));
}
}
}
20 changes: 20 additions & 0 deletions src/UnitTest/UnitTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Agent.Cocohub\Agent.Cocohub.csproj" />
</ItemGroup>

</Project>

0 comments on commit c299315

Please sign in to comment.