Skip to content

Commit

Permalink
Moving Logging from Common.Logging to Microsoft.Extensions.Logging
Browse files Browse the repository at this point in the history
For older versions of .net a custom ILogger has been created  in Nethereum.JsonRpc.Client which anyone can implement for simple logging. All tests use now only netcoreapp3.1 instead of netcoerapp2.0
  • Loading branch information
juanfranblanco committed Sep 8, 2022
1 parent f5f4792 commit 8efdef8
Show file tree
Hide file tree
Showing 61 changed files with 390 additions and 238 deletions.
5 changes: 4 additions & 1 deletion FxOutput/Nethereum.LiteFx/Nethereum.LiteFx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
<PropertyGroup>
<TargetFrameworks>net5.0;netcoreapp3.1;netstandard2.0;netstandard2.1</TargetFrameworks>
</PropertyGroup>


<ItemGroup Condition=" '$(TargetFramework)' != 'net35' AND '$(TargetFramework)' != 'netstandard1.1' AND '$(TargetFramework)' != 'net451' AND '$(TargetFramework)' != 'netcoreapp2.1' ">
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
</ItemGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);LITE;BYTECODELITE</DefineConstants>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 5 additions & 3 deletions src/Nethereum.Besu/Web3Besu.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Net.Http.Headers;
using Common.Logging;
#if NETSTANDARD2_0_OR_GREATER || NETCOREAPP3_1_OR_GREATER || NET461_OR_GREATER || NET5_0_OR_GREATER
using Microsoft.Extensions.Logging;
#endif
using Nethereum.JsonRpc.Client;
using Nethereum.RPC.Accounts;

Expand All @@ -11,7 +13,7 @@ public Web3Besu(IClient client) : base(client)
{
}

public Web3Besu(string url = @"http://localhost:8545/", ILog log = null,
public Web3Besu(string url = @"http://localhost:8545/", ILogger log = null,
AuthenticationHeaderValue authenticationHeader = null) : base(url, log, authenticationHeader)
{
}
Expand All @@ -20,7 +22,7 @@ public Web3Besu(IAccount account, IClient client) : base(account, client)
{
}

public Web3Besu(IAccount account, string url = @"http://localhost:8545/", ILog log = null,
public Web3Besu(IAccount account, string url = @"http://localhost:8545/", ILogger log = null,
AuthenticationHeaderValue authenticationHeader = null) : base(account, url, log, authenticationHeader)
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using Common.Logging;
#if NETSTANDARD2_0_OR_GREATER || NETCOREAPP3_1_OR_GREATER || NET461_OR_GREATER || NET5_0_OR_GREATER
using Microsoft.Extensions.Logging;
#else
using Nethereum.JsonRpc.Client;
#endif
using Nethereum.BlockchainProcessing.BlockProcessing;
using Nethereum.BlockchainProcessing.ProgressRepositories;
using Nethereum.RPC.Eth.Blocks;
Expand All @@ -8,7 +12,7 @@ namespace Nethereum.BlockchainProcessing
public class BlockchainCrawlingProcessor : BlockchainProcessor
{
public BlockCrawlOrchestrator Orchestrator => (BlockCrawlOrchestrator)BlockchainProcessingOrchestrator;
public BlockchainCrawlingProcessor(BlockCrawlOrchestrator blockchainProcessingOrchestrator, IBlockProgressRepository blockProgressRepository, ILastConfirmedBlockNumberService lastConfirmedBlockNumberService, ILog log = null):base(blockchainProcessingOrchestrator, blockProgressRepository, lastConfirmedBlockNumberService, log)
public BlockchainCrawlingProcessor(BlockCrawlOrchestrator blockchainProcessingOrchestrator, IBlockProgressRepository blockProgressRepository, ILastConfirmedBlockNumberService lastConfirmedBlockNumberService, ILogger log = null):base(blockchainProcessingOrchestrator, blockProgressRepository, lastConfirmedBlockNumberService, log)
{

}
Expand Down
14 changes: 9 additions & 5 deletions src/Nethereum.BlockchainProcessing/BlockchainProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System.Numerics;
using System.Threading;
using System.Threading.Tasks;
using Common.Logging;
#if NETSTANDARD2_0_OR_GREATER || NETCOREAPP3_1_OR_GREATER || NET461_OR_GREATER || NET5_0_OR_GREATER
using Microsoft.Extensions.Logging;
#else
using Nethereum.JsonRpc.Client;
#endif
using Nethereum.BlockchainProcessing.Orchestrator;
using Nethereum.BlockchainProcessing.ProgressRepositories;
using Nethereum.RPC.Eth.Blocks;
Expand All @@ -13,9 +17,9 @@ public class BlockchainProcessor
protected IBlockchainProcessingOrchestrator BlockchainProcessingOrchestrator { get; set; }
private IBlockProgressRepository _blockProgressRepository;
private ILastConfirmedBlockNumberService _lastConfirmedBlockNumberService;
private ILog _log;
private ILogger _log;

public BlockchainProcessor(IBlockchainProcessingOrchestrator blockchainProcessingOrchestrator, IBlockProgressRepository blockProgressRepository, ILastConfirmedBlockNumberService lastConfirmedBlockNumberService, ILog log = null)
public BlockchainProcessor(IBlockchainProcessingOrchestrator blockchainProcessingOrchestrator, IBlockProgressRepository blockProgressRepository, ILastConfirmedBlockNumberService lastConfirmedBlockNumberService, ILogger log = null)
{
BlockchainProcessingOrchestrator = blockchainProcessingOrchestrator;
_blockProgressRepository = blockProgressRepository;
Expand Down Expand Up @@ -117,11 +121,11 @@ private async Task UpdateLastBlockProcessedAsync(BigInteger? lastBlock)
if (lastBlock != null)
{
await _blockProgressRepository.UpsertProgressAsync(lastBlock.Value).ConfigureAwait(false);
_log?.Info($"Last Block Processed: {lastBlock}");
_log?.LogInformation($"Last Block Processed: {lastBlock}");
}
else
{
_log?.Info($"No Block Processed");
_log?.LogInformation($"No Block Processed");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System;
using Common.Logging;
#if NETSTANDARD2_0_OR_GREATER || NETCOREAPP3_1_OR_GREATER || NET461_OR_GREATER || NET5_0_OR_GREATER
using Microsoft.Extensions.Logging;
#else
using Nethereum.JsonRpc.Client;
#endif
using Nethereum.BlockchainProcessing.BlockProcessing;
using Nethereum.BlockchainProcessing.BlockStorage;
using Nethereum.BlockchainProcessing.BlockStorage.Repositories;
Expand All @@ -23,7 +27,7 @@ public BlockchainBlockProcessingService(IEthApiContractService ethApiContractSer
public BlockchainCrawlingProcessor CreateBlockProcessor(
Action<BlockProcessingSteps> stepsConfiguration,
uint minimumBlockConfirmations,
ILog log = null) => CreateBlockProcessor(
ILogger log = null) => CreateBlockProcessor(
new InMemoryBlockchainProgressRepository(),
stepsConfiguration,
minimumBlockConfirmations,
Expand All @@ -33,7 +37,7 @@ public BlockchainBlockProcessingService(IEthApiContractService ethApiContractSer
IBlockProgressRepository blockProgressRepository,
Action<BlockProcessingSteps> stepsConfiguration,
uint minimumBlockConfirmations,
ILog log = null)
ILogger log = null)
{
var processingSteps = new BlockProcessingSteps();
var orchestrator = new BlockCrawlOrchestrator(_ethApiContractService, processingSteps );
Expand All @@ -47,8 +51,8 @@ public BlockchainBlockProcessingService(IEthApiContractService ethApiContractSer
public BlockchainCrawlingProcessor CreateBlockStorageProcessor(
IBlockchainStoreRepositoryFactory blockchainStorageFactory,
uint minimumBlockConfirmations,
Action<BlockProcessingSteps> configureSteps = null,
ILog log = null) => CreateBlockStorageProcessor(
Action<BlockProcessingSteps> configureSteps = null,
ILogger log = null) => CreateBlockStorageProcessor(
blockchainStorageFactory,
null,
minimumBlockConfirmations,
Expand All @@ -61,7 +65,7 @@ public BlockchainBlockProcessingService(IEthApiContractService ethApiContractSer
IBlockProgressRepository blockProgressRepository,
uint minimumBlockConfirmations,
Action<BlockProcessingSteps> configureSteps = null,
ILog log = null)
ILogger log = null)
{
var processingSteps = new BlockStorageProcessingSteps(blockchainStorageFactory);
var orchestrator = new BlockCrawlOrchestrator(_ethApiContractService, processingSteps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
using System.Numerics;
using System.Threading;
using System.Threading.Tasks;
using Common.Logging;
#if NETSTANDARD2_0_OR_GREATER || NETCOREAPP3_1_OR_GREATER || NET461_OR_GREATER || NET5_0_OR_GREATER
using Microsoft.Extensions.Logging;
#else
using Nethereum.JsonRpc.Client;
#endif
using Nethereum.BlockchainProcessing.LogProcessing;
using Nethereum.BlockchainProcessing.Processor;
using Nethereum.BlockchainProcessing.ProgressRepositories;
Expand Down Expand Up @@ -146,7 +150,7 @@ Task StoreLogAsync(EventLog<TEventDTO> eventLog)
uint minimumBlockConfirmations,
Func<EventLog<TEventDTO>, bool> criteria = null,
IBlockProgressRepository blockProgressRepository = null,
ILog log = null) where TEventDTO : class, new() =>
ILogger log = null) where TEventDTO : class, new() =>
CreateProcessor(new[] {new EventLogProcessorHandler<TEventDTO>(action, criteria)}, minimumBlockConfirmations,
new FilterInputBuilder<TEventDTO>().Build(), blockProgressRepository, log);

Expand All @@ -157,7 +161,7 @@ Task StoreLogAsync(EventLog<TEventDTO> eventLog)
uint minimumBlockConfirmations,
Func<EventLog<TEventDTO>, bool> criteria = null,
IBlockProgressRepository blockProgressRepository = null,
ILog log = null) where TEventDTO : class, new() =>
ILogger log = null) where TEventDTO : class, new() =>
CreateProcessor(new[]
{
new EventLogProcessorHandler<TEventDTO>(action, criteria)
Expand All @@ -175,7 +179,7 @@ Task StoreLogAsync(EventLog<TEventDTO> eventLog)
uint minimumBlockConfirmations,
Func<EventLog<TEventDTO>, bool> criteria = null,
IBlockProgressRepository blockProgressRepository = null,
ILog log = null) where TEventDTO : class, new() =>
ILogger log = null) where TEventDTO : class, new() =>
CreateProcessor(new[] {new EventLogProcessorHandler<TEventDTO>(action, criteria)}, minimumBlockConfirmations,
new FilterInputBuilder<TEventDTO>().Build(contractAddresses), blockProgressRepository, log);

Expand All @@ -184,7 +188,7 @@ Task StoreLogAsync(EventLog<TEventDTO> eventLog)
uint minimumBlockConfirmations,
Func<EventLog<TEventDTO>, Task<bool>> criteria = null,
IBlockProgressRepository blockProgressRepository = null,
ILog log = null) where TEventDTO : class, new() =>
ILogger log = null) where TEventDTO : class, new() =>
CreateProcessor(new[] {new EventLogProcessorHandler<TEventDTO>(action, criteria)}, minimumBlockConfirmations,
new FilterInputBuilder<TEventDTO>().Build(), blockProgressRepository, log);

Expand All @@ -195,7 +199,7 @@ Task StoreLogAsync(EventLog<TEventDTO> eventLog)
uint minimumBlockConfirmations,
Func<EventLog<TEventDTO>, Task<bool>> criteria = null,
IBlockProgressRepository blockProgressRepository = null,
ILog log = null) where TEventDTO : class, new() =>
ILogger log = null) where TEventDTO : class, new() =>
CreateProcessor(new[] {new EventLogProcessorHandler<TEventDTO>(action, criteria)}, minimumBlockConfirmations,
new FilterInputBuilder<TEventDTO>().Build(new[] {contractAddress}), blockProgressRepository, log);

Expand All @@ -205,7 +209,7 @@ Task StoreLogAsync(EventLog<TEventDTO> eventLog)
uint minimumBlockConfirmations,
Func<EventLog<TEventDTO>, Task<bool>> criteria = null,
IBlockProgressRepository blockProgressRepository = null,
ILog log = null) where TEventDTO : class, new() =>
ILogger log = null) where TEventDTO : class, new() =>
CreateProcessor(new[] {new EventLogProcessorHandler<TEventDTO>(action, criteria)}, minimumBlockConfirmations,
new FilterInputBuilder<TEventDTO>().Build(contractAddresses), blockProgressRepository, log);

Expand All @@ -214,7 +218,7 @@ Task StoreLogAsync(EventLog<TEventDTO> eventLog)
string[] contractAddresses,
uint minimumBlockConfirmations,
IBlockProgressRepository blockProgressRepository = null,
ILog log = null) where TEventDTO : class =>
ILogger log = null) where TEventDTO : class =>
CreateProcessor(new[] {logProcessor}, minimumBlockConfirmations, new FilterInputBuilder<TEventDTO>().Build(contractAddresses),
blockProgressRepository, log);

Expand All @@ -225,7 +229,7 @@ Task StoreLogAsync(EventLog<TEventDTO> eventLog)
uint minimumBlockConfirmations,
Func<FilterLog, bool> criteria = null,
IBlockProgressRepository blockProgressRepository = null,
ILog log = null) => CreateProcessor(new[] {new ProcessorHandler<FilterLog>(action, criteria)}, minimumBlockConfirmations,
ILogger log = null) => CreateProcessor(new[] {new ProcessorHandler<FilterLog>(action, criteria)}, minimumBlockConfirmations,
new NewFilterInput {Address = new[] {contractAddress}}, blockProgressRepository, log);

public BlockchainProcessor CreateProcessorForContracts(
Expand All @@ -235,7 +239,7 @@ Task StoreLogAsync(EventLog<TEventDTO> eventLog)
uint minimumBlockConfirmations,
Func<FilterLog, bool> criteria = null,
IBlockProgressRepository blockProgressRepository = null,
ILog log = null) => CreateProcessor(new[] {new ProcessorHandler<FilterLog>(action, criteria)}, minimumBlockConfirmations,
ILogger log = null) => CreateProcessor(new[] {new ProcessorHandler<FilterLog>(action, criteria)}, minimumBlockConfirmations,
new NewFilterInput {Address = contractAddresses}, blockProgressRepository, log);


Expand All @@ -247,7 +251,7 @@ Task StoreLogAsync(EventLog<TEventDTO> eventLog)
Func<FilterLog, bool> criteria = null,
NewFilterInput filter = null,
IBlockProgressRepository blockProgressRepository = null,
ILog log = null) => CreateProcessor(new[] {new ProcessorHandler<FilterLog>(action, criteria)}, minimumBlockConfirmations, filter,
ILogger log = null) => CreateProcessor(new[] {new ProcessorHandler<FilterLog>(action, criteria)}, minimumBlockConfirmations, filter,
blockProgressRepository, log);

//async action and criteria
Expand All @@ -258,7 +262,7 @@ Task StoreLogAsync(EventLog<TEventDTO> eventLog)
Func<FilterLog, Task<bool>> criteria = null,
NewFilterInput filter = null,
IBlockProgressRepository blockProgressRepository = null,
ILog log = null) => CreateProcessor(new[] {new ProcessorHandler<FilterLog>(action, criteria)}, minimumBlockConfirmations, filter,
ILogger log = null) => CreateProcessor(new[] {new ProcessorHandler<FilterLog>(action, criteria)}, minimumBlockConfirmations, filter,
blockProgressRepository, log);

//single processor
Expand All @@ -268,7 +272,7 @@ Task StoreLogAsync(EventLog<TEventDTO> eventLog)
uint minimumBlockConfirmations,
NewFilterInput filter = null,
IBlockProgressRepository blockProgressRepository = null,
ILog log = null) => CreateProcessor(new[] {logProcessor}, minimumBlockConfirmations, filter, blockProgressRepository, log);
ILogger log = null) => CreateProcessor(new[] {logProcessor}, minimumBlockConfirmations, filter, blockProgressRepository, log);

//multi processor
public BlockchainProcessor CreateProcessor(
Expand All @@ -277,7 +281,7 @@ Task StoreLogAsync(EventLog<TEventDTO> eventLog)
uint minimumBlockConfirmations,
NewFilterInput filter = null,
IBlockProgressRepository blockProgressRepository = null,
ILog log = null, int defaultNumberOfBlocksPerRequest = 100, int retryWeight = 0)
ILogger log = null, int defaultNumberOfBlocksPerRequest = 100, int retryWeight = 0)
{
var orchestrator = new LogOrchestrator(_ethApiContractService, logProcessors, filter, defaultNumberOfBlocksPerRequest, retryWeight);

Expand Down

0 comments on commit 8efdef8

Please sign in to comment.