Skip to content

Commit

Permalink
change provider of log4net
Browse files Browse the repository at this point in the history
add support to change db type in configuration
add run configurations
fix log level
  • Loading branch information
loning committed May 23, 2020
1 parent ed24619 commit 3c19ee8
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 29 deletions.
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,14 @@ coverage*.xml
scripts/patcher/*

tools
.dotnet
.dotnet
!.idea/
.idea/.idea.AElf/.idea/contentModel.xml
.idea/.idea.AElf/.idea/encodings.xml
.idea/.idea.AElf/.idea/indexLayout.xml
.idea/.idea.AElf/.idea/misc.xml
.idea/.idea.AElf/.idea/modules.xml
.idea/.idea.AElf/.idea/projectSettingsUpdater.xml
.idea/.idea.AElf/.idea/vcs.xml
.idea/.idea.AElf/.idea/workspace.xml
.idea/.idea.AElf/riderModule.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/AElf.Blockchains.MainChain/MainChainAElfModule.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using AElf.Blockchains.BasicBaseChain;
using AElf.Database;
using AElf.Kernel.Infrastructure;
using AElf.Kernel.SmartContractInitialization;
using AElf.Modularity;
using AElf.OS.Node.Application;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
Expand All @@ -26,6 +29,18 @@ public override void ConfigureServices(ServiceConfigurationContext context)
var services = context.Services;
services.AddTransient<IContractDeploymentListProvider, MainChainContractDeploymentListProvider>();
services.AddTransient<IGenesisSmartContractDtoProvider, MainChainGenesisSmartContractDtoProvider>();

var config = context.Services.GetConfiguration();

if (config.GetConnectionString("BlockchainDb") == "InMemory")
{
services.AddKeyValueDbContext<BlockchainKeyValueDbContext>(p => p.UseInMemoryDatabase());
}

if (config.GetConnectionString("StateDb") == "InMemory")
{
services.AddKeyValueDbContext<StateKeyValueDbContext>(p => p.UseInMemoryDatabase());
}
}
}
}
10 changes: 10 additions & 0 deletions src/AElf.Launcher/AElf.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,31 @@
<ItemGroup>
<Content Include="appsettings.Development.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.MainChain.MainNet.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.MainChain.TestNet.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.MainChain.CustomNet.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.Production.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.SideChain.CustomNet.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
7 changes: 6 additions & 1 deletion src/AElf.Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Reflection;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging.Abstractions;

Expand Down Expand Up @@ -32,6 +33,7 @@ private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
else
return null;
}

var assembly = Assembly.LoadFrom(assemblyPath);
return assembly;
}
Expand All @@ -55,7 +57,10 @@ public static void Main(string[] args)
// create default https://github.com/aspnet/MetaPackages/blob/master/src/Microsoft.AspNetCore/WebHost.cs
private static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging(builder => { builder.ClearProviders(); })
.ConfigureLogging(builder =>
{
builder.ClearProviders();
})
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); })
.UseAutofac();
}
Expand Down
9 changes: 7 additions & 2 deletions src/AElf.Launcher/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
"System": "Error",
"Microsoft": "Error",
"AElf.Kernel.Consensus": "Trace"
}
},
"ConnectionStrings": {
"BlockchainDb": "redis://localhost:6379?db=1",
"StateDb": "redis://localhost:6379?db=1"
}
}
6 changes: 6 additions & 0 deletions src/AElf.Launcher/appsettings.Production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ConnectionStrings": {
"BlockchainDb": "redis://localhost:6379?db=1",
"StateDb": "redis://localhost:6379?db=1"
}
}
11 changes: 11 additions & 0 deletions src/AElf.Launcher/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,16 @@
},
"Transaction": {
"PoolLimit": 10240
},

"Logging": {
"LogLevel": {
"Default": "Information",
"System": "Error",
"Microsoft": "Error",
"AElf.OS" : "Information",
"AElf.Kernel.Consensus" : "Information",
"AElf" : "Information"
}
}
}
2 changes: 1 addition & 1 deletion src/AElf.RuntimeSetup/AElf.RuntimeSetup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="apache.log4net.Extensions.Logging" Version="2.0.0.12" />
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="3.1.0" />
<PackageReference Include="Volo.Abp.AspNetCore" Version="2.7.0" />
</ItemGroup>

Expand Down
28 changes: 4 additions & 24 deletions src/AElf.RuntimeSetup/RuntimeSetupAElfModule.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.IO;
using apache.log4net.Extensions.Logging;
using AElf.Modularity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Volo.Abp.Modularity;
using System.Linq;
using Microsoft.Extensions.Configuration;

namespace AElf.RuntimeSetup
{
Expand All @@ -16,31 +16,11 @@ public class RuntimeSetupAElfModule : AElfModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var variables = Environment.GetEnvironmentVariables();
var keys = variables.Keys.Cast<string>().Select(p => new {Ori = p, Uni = p.ToUpper()}).GroupBy(p => p.Uni).ToList();
foreach (var key in keys)
{
if (key.Count() <= 1) continue;
var list = key.ToList();
for (var i = 1; i < list.Count; i++)
{
Environment.SetEnvironmentVariable(list[i].Ori, null);
}
}

var log4NetConfigFile = Path.Combine(context.Services.GetHostingEnvironment().ContentRootPath, "log4net.config");
if (!File.Exists(log4NetConfigFile))
{
log4NetConfigFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config");
}

context.Services.AddLogging(builder =>
{
builder.AddLog4Net(new Log4NetSettings()
{
ConfigFile = log4NetConfigFile
});

builder.AddConfiguration(context.Services.GetConfiguration().GetSection("Logging"));

builder.AddLog4Net();
builder.SetMinimumLevel(LogLevel.Debug);
});
}
Expand Down

0 comments on commit 3c19ee8

Please sign in to comment.