Skip to content

Commit

Permalink
Upgrade to .NET-5.0
Browse files Browse the repository at this point in the history
TomatoLog version 2.0
  • Loading branch information
lianggx committed Nov 24, 2020
1 parent deca8b0 commit 8301185
Show file tree
Hide file tree
Showing 115 changed files with 13,487 additions and 15,606 deletions.
Binary file not shown.
600 changes: 0 additions & 600 deletions TomatoLog.Server/Plugins/TomatoLog.ToES/TomatoLog.ToES.deps.json

This file was deleted.

Binary file not shown.
Binary file not shown.
566 changes: 0 additions & 566 deletions TomatoLog.Server/Plugins/TomatoLog.ToFile/TomatoLog.ToFile.deps.json

This file was deleted.

Binary file not shown.
Binary file not shown.
2,021 changes: 0 additions & 2,021 deletions TomatoLog.Server/Plugins/TomatoLog.ToMongoDB/TomatoLog.ToMongoDB.deps.json

This file was deleted.

Binary file not shown.
14 changes: 7 additions & 7 deletions TomatoLog.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example", "samples\Example\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TomatoLog.Common", "src\TomatoLog.Common\TomatoLog.Common.csproj", "{C21E96DA-BC42-4DEF-A2B9-AFDA98F0A207}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TomatoLog.Server", "src\TomatoLog.Server\TomatoLog.Server.csproj", "{776BA613-7BFC-40B5-8CB6-E070CCF85128}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "clients", "clients", "{429764D8-8D21-45EB-A13D-71A580D8BF1C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "plugins", "plugins", "{354CF735-FC8A-4F97-9962-B071184176F1}"
Expand Down Expand Up @@ -56,6 +54,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TomatoLog.Client.Kafka", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TomatoLog.Client.Kafka.XUnitTest", "test\clients\TomatoLog.Client.Kafka.XUnitTest\TomatoLog.Client.Kafka.XUnitTest.csproj", "{76007F20-1E3E-4628-8E42-C54440924EAB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TomatoLog.Server", "src\TomatoLog.Server\TomatoLog.Server.csproj", "{152249F0-90C4-4E4A-9850-9804A1DF6E8D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -70,10 +70,6 @@ Global
{C21E96DA-BC42-4DEF-A2B9-AFDA98F0A207}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C21E96DA-BC42-4DEF-A2B9-AFDA98F0A207}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C21E96DA-BC42-4DEF-A2B9-AFDA98F0A207}.Release|Any CPU.Build.0 = Release|Any CPU
{776BA613-7BFC-40B5-8CB6-E070CCF85128}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{776BA613-7BFC-40B5-8CB6-E070CCF85128}.Debug|Any CPU.Build.0 = Debug|Any CPU
{776BA613-7BFC-40B5-8CB6-E070CCF85128}.Release|Any CPU.ActiveCfg = Release|Any CPU
{776BA613-7BFC-40B5-8CB6-E070CCF85128}.Release|Any CPU.Build.0 = Release|Any CPU
{5EF304C4-A7A2-4A79-93A8-0EE5720F5CDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5EF304C4-A7A2-4A79-93A8-0EE5720F5CDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5EF304C4-A7A2-4A79-93A8-0EE5720F5CDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -126,14 +122,17 @@ Global
{76007F20-1E3E-4628-8E42-C54440924EAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76007F20-1E3E-4628-8E42-C54440924EAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76007F20-1E3E-4628-8E42-C54440924EAB}.Release|Any CPU.Build.0 = Release|Any CPU
{152249F0-90C4-4E4A-9850-9804A1DF6E8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{152249F0-90C4-4E4A-9850-9804A1DF6E8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{152249F0-90C4-4E4A-9850-9804A1DF6E8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{152249F0-90C4-4E4A-9850-9804A1DF6E8D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4193C277-166D-43A7-AD87-DD96C1F86D58} = {D309F82B-8776-4BDB-A2F0-D6D20E6C67A5}
{C21E96DA-BC42-4DEF-A2B9-AFDA98F0A207} = {299FA2FB-6403-4AF5-ABC8-04E7F9EBA4DB}
{776BA613-7BFC-40B5-8CB6-E070CCF85128} = {299FA2FB-6403-4AF5-ABC8-04E7F9EBA4DB}
{429764D8-8D21-45EB-A13D-71A580D8BF1C} = {299FA2FB-6403-4AF5-ABC8-04E7F9EBA4DB}
{354CF735-FC8A-4F97-9962-B071184176F1} = {299FA2FB-6403-4AF5-ABC8-04E7F9EBA4DB}
{5EF304C4-A7A2-4A79-93A8-0EE5720F5CDB} = {354CF735-FC8A-4F97-9962-B071184176F1}
Expand All @@ -151,6 +150,7 @@ Global
{8C4412F5-920F-459C-AF86-0763FFCBD410} = {00E8288E-183B-4091-95C6-4CB89AEDEB3A}
{F05B796C-672E-4D9F-8E2E-95E457138334} = {429764D8-8D21-45EB-A13D-71A580D8BF1C}
{76007F20-1E3E-4628-8E42-C54440924EAB} = {A6BBD0C7-C5A8-4D2C-AD06-2CF6CAFB5817}
{152249F0-90C4-4E4A-9850-9804A1DF6E8D} = {299FA2FB-6403-4AF5-ABC8-04E7F9EBA4DB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4D09D4E2-2C4A-4568-A894-61269497475C}
Expand Down
10 changes: 3 additions & 7 deletions samples/Example/Example.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\..\src\clients\TomatoLog.Client.RabbitMQ\TomatoLog.Client.RabbitMQ.csproj" />
</ItemGroup>
Expand Down
16 changes: 11 additions & 5 deletions samples/Example/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System.Text.Json;
using TomatoLog.Client.RabbitMQ;
using TomatoLog.Common.Config;
using TomatoLog.Common.Interface;
using TomatoLog.Client.Extensions;
using Microsoft.Extensions.Hosting;

namespace Example
{
Expand All @@ -36,19 +37,24 @@ public void ConfigureServices(IServiceCollection services)
return client;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddControllers();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory factory, ITomatoLogClient logClient)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory factory, ITomatoLogClient logClient)
{
factory.UseTomatoLogger(logClient);
if (env.IsDevelopment())
if (env.EnvironmentName == Environments.Development)
{
app.UseDeveloperExceptionPage();
}

app.UseMvc();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
11 changes: 6 additions & 5 deletions src/TomatoLog.Common/TomatoLog.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseUrl>https://github.com/lianggx/TomatoLog/blob/master/LICENSE</PackageLicenseUrl>
<Version>1.1.0</Version>
<PackageLicenseUrl></PackageLicenseUrl>
<Version>2.0</Version>
<Authors>lianggx</Authors>
<Product>TomatoLog</Product>
<PackageProjectUrl>https://github.com/lianggx/TomatoLog</PackageProjectUrl>
<RepositoryUrl>https://github.com/lianggx/TomatoLog.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="NLog" Version="4.5.11" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.4.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.0" />
<PackageReference Include="System.Text.Json" Version="5.0.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/TomatoLog.Common/Utilities/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class Check
{
public static T NotNull<T>(T value, string parameterName)
{
if (ReferenceEquals(value, null))
if (value == null)
{
NotEmpty(parameterName, nameof(parameterName));

Expand Down
20 changes: 20 additions & 0 deletions src/TomatoLog.Common/Utilities/JsonConverterDateTimeParse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace TomatoLog.Common.Utilities
{
public class JsonConverterDateTimeParse : JsonConverter<DateTime>
{
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return DateTime.Parse(reader.GetString());
}
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString("yyyy-MM-dd HH:mm:ss.FFFF"));
}
}
}
3 changes: 3 additions & 0 deletions src/TomatoLog.Common/Utilities/LogMessage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging;
using System;
using System.Text.Json.Serialization;

namespace TomatoLog.Common.Utilities
{
Expand All @@ -8,6 +9,7 @@ public class LogMessage
public int EventId { get; set; }
public string ProjectName { get; set; }
public string ProjectLabel { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter))]
public LogLevel LogLevel { get; set; }
public string Version { get; set; }
public string IP { get; set; }
Expand All @@ -16,6 +18,7 @@ public class LogMessage
public string ThreadId { get; set; }
public string ProcessId { get; set; }
public string ProcessName { get; set; }
[JsonConverter(typeof(JsonConverterDateTimeParse))]
public DateTime Timestamp { get; set; }
public string UserName { get; set; }
public string ErrorMessage { get; set; }
Expand Down
12 changes: 3 additions & 9 deletions src/TomatoLog.Server/BLL/BaseConfigManager.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using TomatoLog.Server.Models;
using System.Text.Json;

namespace TomatoLog.Server.BLL
{
Expand All @@ -22,15 +16,15 @@ public BaseConfigManager(IConfiguration configuration)
public T Load()
{
var json = System.IO.File.ReadAllText(ConfigFile);
this.ConfigObject = JsonConvert.DeserializeObject<T>(json);
this.ConfigObject = JsonSerializer.Deserialize<T>(json);

return ConfigObject;
}

public void Save()
{
var json = System.IO.File.ReadAllText(ConfigFile);
System.IO.File.WriteAllText(ConfigFile, JsonConvert.SerializeObject(this.ConfigObject));
System.IO.File.WriteAllText(ConfigFile, JsonSerializer.Serialize(this.ConfigObject));
}

public abstract string ConfigFile { get; }
Expand Down
18 changes: 12 additions & 6 deletions src/TomatoLog.Server/BLL/FilterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ public class FilterService
private readonly SysConfigManager sysManager;
private readonly ProConfigManager proManager;
private readonly ILogger logger;
private readonly HttpClient httpClient;

public FilterService(IConfiguration configuration, IDistributedCache cache, SysConfigManager sysManager, ProConfigManager proManager, ILogger logger)
public FilterService(IConfiguration configuration,
IDistributedCache cache,
SysConfigManager sysManager,
ProConfigManager proManager,
ILogger logger,
HttpClient httpClient)
{
this.configuration = configuration;
this.cache = cache;
this.sysManager = sysManager;
this.proManager = proManager;
this.logger = logger;
this.httpClient = httpClient;
}

public async void Filter(LogMessage log)
Expand All @@ -44,7 +51,7 @@ public async void Filter(LogMessage log)
if (sett.Levels != null && sett.Levels.Contains(log.LogLevel.ToString()))
{
var key = $"{log.ProjectName}_{log.LogLevel}";
var count = await cache.GetObjectAsync<int>(key);
int.TryParse(await cache.GetStringAsync(key), out int count);
if ((count + 1) >= sett.Count)
{
Notifier(reportModel, configuration, log);
Expand All @@ -58,18 +65,17 @@ public async void Filter(LogMessage log)
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(sett.Time)
};
await cache.SetObjectAsync(key, ++count, options);
await cache.SetStringAsync(key, (++count).ToString(), options);
}
else
await cache.SetObjectAsync(key, ++count);
await cache.SetStringAsync(key, (++count).ToString());
}
}
}

private void Notifier(ReportViewModel repportModel, IConfiguration configuration, LogMessage log)
{
var client = HttpClientFactory.Create();
var notify = new NotifyMonitor(client, configuration, logger, repportModel);
var notify = new NotifyMonitor(httpClient, configuration, logger, repportModel);
notify.SendSms(log);
notify.SendEmail(log);
}
Expand Down
Loading

0 comments on commit 8301185

Please sign in to comment.