Commit 92eb9c0a authored by Jeremy Bokobza's avatar Jeremy Bokobza

Added logging to a rolling file

parent 33ce56ce
......@@ -296,3 +296,4 @@ Thumbs.db
# DNX
project.lock.json
/Breeze/src/Breeze.Daemon/Wallets
/Breeze/src/Breeze.Daemon/Logs
......@@ -16,7 +16,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="1.0.3" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="1.0.1" />
<PackageReference Include="System.ValueTuple" Version="4.3.1" />
<PackageReference Include="Stratis.Bitcoin" Version="1.0.1.8-alpha" />
</ItemGroup>
......
......@@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Logging;
using Microsoft.Extensions.Logging;
using Serilog;
namespace Breeze.Wallet
{
......@@ -11,7 +12,7 @@ namespace Breeze.Wallet
{
private readonly ITracker tracker;
private readonly IWalletManager walletManager;
public WalletFeature(ITracker tracker, IWalletManager walletManager)
{
this.tracker = tracker;
......@@ -19,7 +20,7 @@ namespace Breeze.Wallet
}
public override void Start()
{
{
this.tracker.Initialize();
}
......@@ -39,12 +40,15 @@ namespace Breeze.Wallet
features
.AddFeature<WalletFeature>()
.FeatureServices(services =>
{
services.AddSingleton<ITracker, Tracker>();
services.AddSingleton<ILoggerFactory>(Logs.LoggerFactory);
services.AddSingleton<IWalletManager, WalletManager>();
services.AddSingleton<WalletController>();
});
{
var loggerFactory = Logs.LoggerFactory;
loggerFactory.AddFile("Logs/Breeze-{Date}.json", isJson: true, minimumLevel:LogLevel.Debug, fileSizeLimitBytes: 10000000);
services.AddSingleton<ITracker, Tracker>();
services.AddSingleton<ILoggerFactory>(loggerFactory);
services.AddSingleton<IWalletManager, WalletManager>();
services.AddSingleton<WalletController>();
});
});
return fullNodeBuilder;
......
......@@ -5,6 +5,7 @@ using System.Linq;
using System.Runtime.InteropServices;
using Breeze.Wallet.Helpers;
using Breeze.Wallet.Models;
using Microsoft.Extensions.Logging;
using NBitcoin;
using NBitcoin.DataEncoders;
using NBitcoin.Protocol;
......@@ -37,13 +38,16 @@ namespace Breeze.Wallet
private Dictionary<Script, HdAddress> keysLookup;
private readonly ILogger logger;
/// <summary>
/// Occurs when a transaction is found.
/// </summary>
public event EventHandler<TransactionFoundEventArgs> TransactionFound;
public WalletManager(ConnectionManager connectionManager, Network network, ConcurrentChain chain)
public WalletManager(ILoggerFactory loggerFactory, ConnectionManager connectionManager, Network network, ConcurrentChain chain)
{
this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
this.Wallets = new List<Wallet>();
// find wallets and load them in memory
......@@ -447,7 +451,7 @@ namespace Breeze.Wallet
/// <inheritdoc />
public void ProcessBlock(int height, Block block)
{
Console.WriteLine($"block notification: height: {height}, block hash: {block.Header.GetHash()}, coin type: {this.coinType}");
this.logger.LogDebug($"block notification - height: {height}, hash: {block.Header.GetHash()}, coin: {this.coinType}");
foreach (Transaction transaction in block.Transactions)
{
......@@ -461,7 +465,7 @@ namespace Breeze.Wallet
/// <inheritdoc />
public void ProcessTransaction(Transaction transaction, int? blockHeight = null, Block block = null)
{
Console.WriteLine($"transaction notification: tx hash {transaction.GetHash()}, coin type: {this.coinType}");
this.logger.LogDebug($"transaction received - hash: {transaction.GetHash()}, coin: {this.coinType}");
// check the outputs
foreach (var pubKey in this.keysLookup.Keys)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment