public async void TestLogging() { if (_ethereumClientIntegrationFixture.Geth) { var capturingLoggerAdapter = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = capturingLoggerAdapter; var contractByteCode = "0x6060604052604060405190810160405280600a81526020017f4d756c7469706c6965720000000000000000000000000000000000000000000081526020015060016000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061008c57805160ff19168380011785556100bd565b828001600101855582156100bd579182015b828111156100bc57825182600050559160200191906001019061009e565b5b5090506100e891906100ca565b808211156100e457600081815060009055506001016100ca565b5090565b5050604051602080610303833981016040528080519060200190919050505b806000600050819055505b506101e2806101216000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806340490a901461004f57806375d0c0dc14610072578063c6888fa1146100ed5761004d565b005b61005c6004805050610119565b6040518082815260200191505060405180910390f35b61007f6004805050610141565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156100df5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610103600480803590602001909190505061012b565b6040518082815260200191505060405180910390f35b60006000600050549050610128565b90565b60006000600050548202905061013c565b919050565b60016000508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101da5780601f106101af576101008083540402835291602001916101da565b820191906000526020600020905b8154815290600101906020018083116101bd57829003601f168201915b50505050508156"; var abi = @"[{""constant"":true,""inputs"":[],""name"":""getMultiplier"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""constant"":true,""inputs"":[],""name"":""contractName"",""outputs"":[{""name"":"""",""type"":""string""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""uint256""}],""type"":""constructor""}]"; var senderAddress = AccountFactory.Address; var web3 = new Web3.Web3(_ethereumClientIntegrationFixture.GetWeb3().TransactionManager.Account, new RpcClient(new Uri("http://localhost:8545"), null, null, null, LogManager.GetLogger <ILog>())); ////deploy the contract, including abi and a paramter of 7. //var transactionHash = await web3.Eth.DeployContract.SendRequestAsync(abi, contractByteCode, senderAddress, // new HexBigInteger(900000), 7); //Assert.Contains("eth_getTransactionCount", capturingLoggerAdapter.LoggerEvents[0].MessageObject.ToString()); //Assert.Contains("RPC Response: 0x", capturingLoggerAdapter.LoggerEvents[1].MessageObject.ToString()); //Assert.Contains("eth_sendRawTransaction", capturingLoggerAdapter.LoggerEvents[2].MessageObject.ToString()); //Assert.Contains("RPC Response: " + transactionHash, capturingLoggerAdapter.LoggerEvents[3].MessageObject.ToString()); BigInteger nonce = 0; try { var transactionHash2 = await web3.Eth.DeployContract.SendRequestAsync(abi, contractByteCode, senderAddress, // lower gas new HexBigInteger(90000), 7); } catch (Exception ex) { } //Parity is: //RPC Response Error: Transaction gas is too low. Assert.Contains("RPC Response Error: intrinsic gas too low", capturingLoggerAdapter.LoggerEvents[6].MessageObject.ToString()); await web3.TransactionManager.Account.NonceService.ResetNonce(); var transactionHash3 = await web3.Eth.DeployContract.SendRequestAsync(abi, contractByteCode, senderAddress, new HexBigInteger(900000), 7); Assert.Contains("eth_getTransactionCount", capturingLoggerAdapter.LoggerEvents[7].MessageObject.ToString()); Assert.Contains("RPC Response: 0x", capturingLoggerAdapter.LoggerEvents[8].MessageObject.ToString()); Assert.Contains("eth_gasPrice", capturingLoggerAdapter.LoggerEvents[9].MessageObject.ToString()); Assert.Contains("RPC Response:", capturingLoggerAdapter.LoggerEvents[10].MessageObject.ToString()); Assert.Contains("eth_sendRawTransaction", capturingLoggerAdapter.LoggerEvents[11].MessageObject.ToString()); Assert.Contains("RPC Response: " + transactionHash3, capturingLoggerAdapter.LoggerEvents[12].MessageObject.ToString()); } }
public void Setup() { originalAdapter = LogManager.Adapter; loggerFactoryAdapter = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = loggerFactoryAdapter; exceptionHandlerAdvice = new ExceptionHandlerAdvice(); }
public void RoutesToCommonLogging() { // CommonLoggingAppender appender = new CommonLoggingAppender(); // appender.Layout = new PatternLayout("%level - %class.%method: %message"); // BasicConfigurator.Configure(stm); Stream stm = this.GetType().Assembly.GetManifestResourceStream(this.GetType().FullName + "_log4net.config.xml"); XmlConfigurator.Configure(stm); CapturingLoggerFactoryAdapter adapter = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = adapter; string message = "testmessage"; Exception exception = new Exception("testexception"); adapter.ClearLastEvent(); log4net.LogManager.GetLogger(this.GetType()).Debug(message, exception); Assert.AreEqual(this.GetType().FullName, adapter.LastEvent.Source.Name); Assert.AreEqual(string.Format("{0} - {1}.{2}: {3}", Level.Debug, this.GetType().FullName, MethodBase.GetCurrentMethod().Name, message), adapter.LastEvent.MessageObject.ToString()); Assert.AreSame(exception, adapter.LastEvent.Exception); adapter.ClearLastEvent(); log4net.LogManager.GetLogger(this.GetType()).Warn(message, exception); Assert.AreEqual(this.GetType().FullName, adapter.LastEvent.Source.Name); Assert.AreEqual(string.Format("{0} - {1}.{2}: {3}", Level.Warn, this.GetType().FullName, MethodBase.GetCurrentMethod().Name, message), adapter.LastEvent.MessageObject.ToString()); Assert.AreSame(exception, adapter.LastEvent.Exception); }
public async Task UnderflowInt256TestingEncoding() { var capturingLoggerAdapter = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = capturingLoggerAdapter; var web3 = GetWeb3(); var deploymentReceipt = await web3.Eth.GetContractDeploymentHandler <TestDeployment>() .SendRequestAndWaitForReceiptAsync().ConfigureAwait(false); var contractHandler = web3.Eth.GetContractHandler(deploymentReceipt.ContractAddress); for (var i = 1; i < 1000000; i = i + 100000) { for (var x = 0; x < 100; x++) { var testAmount = i + x; var result = await contractHandler.QueryAsync <UnderflowInt256ByQuantityFunction, BigInteger>( new UnderflowInt256ByQuantityFunction() { ValueToAddToMinInt256 = testAmount * -1, Value = IntType.MIN_INT256_VALUE + testAmount } ).ConfigureAwait(false); Assert.Equal("RPC Response: 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", capturingLoggerAdapter.LastEvent.MessageObject.ToString()); Assert.Equal(-1, result); } } }
public void RedirectsToCommonLogging() { CapturingLoggerFactoryAdapter testLoggerFactoryAdapter = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = testLoggerFactoryAdapter; // force entlib logging init Logger.Write("init"); var listener = (CommonLoggingEntlibTraceListener)((TraceListenerWrapper)EnterpriseLibraryContainer.Current.GetInstance <TraceListener>("Test Capturing Listener")).InnerTraceListener; // ensure external configuration didn't change // change to starts with because entlib now wraps all listeners and changes the name Assert.IsTrue(listener.Name.StartsWith("Test Capturing Listener")); LogEntry logEntry = new LogEntry(); logEntry.Categories.Add("mycategory"); logEntry.Message = "testmessage"; ILogFormatter formatter = listener.Formatter; string s = formatter.Format(logEntry); Assert.AreEqual("Category: mycategory, Message: testmessage", s); // note that output depends on the formatter configured for the entlib listener! Logger.Write("message1"); Assert.AreEqual("Category: General, Message: message1", testLoggerFactoryAdapter.LastEvent.RenderedMessage); Assert.AreEqual(LogLevel.Info, testLoggerFactoryAdapter.LastEvent.Level); Logger.Write("message2", "custom category", -1, -1, TraceEventType.Warning); Assert.AreEqual("Category: custom category, Message: message2", testLoggerFactoryAdapter.LastEvent.RenderedMessage); Assert.AreEqual("Test Capturing Listener/All Events", testLoggerFactoryAdapter.LastEvent.Source.Name); Assert.AreEqual(LogLevel.Warn, testLoggerFactoryAdapter.LastEvent.Level); }
public void RedirectsToCommonLogging() { CapturingLoggerFactoryAdapter testLoggerFactoryAdapter = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = testLoggerFactoryAdapter; // force entlib logging init Logger.Write("init"); // ensure external configuration didn't change Assert.AreEqual("Test Capturing Listener", TestCommonLoggingEntlibTraceListener.Instance.Name); LogEntry logEntry = new LogEntry(); logEntry.Categories.Add("mycategory"); logEntry.Message = "testmessage"; ILogFormatter formatter = TestCommonLoggingEntlibTraceListener.Instance.Formatter; string s = formatter.Format(logEntry); Assert.AreEqual("Category: mycategory, Message: testmessage", s); using (TestCommonLoggingEntlibTraceListener.Instance.Capture()) { // note that output depends on the formatter configured for the entlib listener! Logger.Write("message1"); Assert.AreEqual("Category: General, Message: message1", testLoggerFactoryAdapter.LastEvent.RenderedMessage); Assert.AreEqual(LogLevel.Info, testLoggerFactoryAdapter.LastEvent.Level); Logger.Write("message2", "custom category", -1, -1, TraceEventType.Warning); Assert.AreEqual("Category: custom category, Message: message2", testLoggerFactoryAdapter.LastEvent.RenderedMessage); Assert.AreEqual("Test Capturing Listener/All Events", testLoggerFactoryAdapter.LastEvent.Source.Name); Assert.AreEqual(LogLevel.Warn, testLoggerFactoryAdapter.LastEvent.Level); } }
public void TestAdapter() { var commonLoggingCapture = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = commonLoggingCapture; var ourAdapter = LdCommonLogging.Adapter; var logger1 = ourAdapter.Logger("things"); var logger2 = logger1.SubLogger("stuff"); logger1.Debug("d0"); logger1.Debug("d1,{0}", "a"); logger1.Debug("d2,{0},{1}", "a", "b"); logger1.Debug("d3,{0},{1},{2}", "a", "b", "c"); logger1.Info("i0"); logger1.Info("i1,{0}", "a"); logger1.Info("i2,{0},{1}", "a", "b"); logger1.Info("i3,{0},{1},{2}", "a", "b", "c"); logger1.Warn("w0"); logger1.Warn("w1,{0}", "a"); logger1.Warn("w2,{0},{1}", "a", "b"); logger1.Warn("w3,{0},{1},{2}", "a", "b", "c"); logger1.Error("e0"); logger1.Error("e1,{0}", "a"); logger1.Error("e2,{0},{1}", "a", "b"); logger1.Error("e3,{0},{1},{2}", "a", "b", "c"); logger2.Warn("goodbye"); Assert.Collection(commonLoggingCapture.LoggerEvents, ExpectEvent("things", Common.Logging.LogLevel.Debug, "d0"), ExpectEvent("things", Common.Logging.LogLevel.Debug, "d1,a"), ExpectEvent("things", Common.Logging.LogLevel.Debug, "d2,a,b"), ExpectEvent("things", Common.Logging.LogLevel.Debug, "d3,a,b,c"), ExpectEvent("things", Common.Logging.LogLevel.Info, "i0"), ExpectEvent("things", Common.Logging.LogLevel.Info, "i1,a"), ExpectEvent("things", Common.Logging.LogLevel.Info, "i2,a,b"), ExpectEvent("things", Common.Logging.LogLevel.Info, "i3,a,b,c"), ExpectEvent("things", Common.Logging.LogLevel.Warn, "w0"), ExpectEvent("things", Common.Logging.LogLevel.Warn, "w1,a"), ExpectEvent("things", Common.Logging.LogLevel.Warn, "w2,a,b"), ExpectEvent("things", Common.Logging.LogLevel.Warn, "w3,a,b,c"), ExpectEvent("things", Common.Logging.LogLevel.Error, "e0"), ExpectEvent("things", Common.Logging.LogLevel.Error, "e1,a"), ExpectEvent("things", Common.Logging.LogLevel.Error, "e2,a,b"), ExpectEvent("things", Common.Logging.LogLevel.Error, "e3,a,b,c"), ExpectEvent("things.stuff", Common.Logging.LogLevel.Warn, "goodbye") ); }
public override void Load() { var capturingLoggerAdapter = new CapturingLoggerFactoryAdapter(); Bind <CapturingLoggerFactoryAdapter>().ToConstant(capturingLoggerAdapter); // create the loggers var consoleLogger = new ConsoleOutLogger("Seeder", LogLevel.All, true, true, false, "yyyy/MM/dd hh:mm:ss"); var capturingLogger = capturingLoggerAdapter.GetLogger("Seeder"); var allLoggers = new List <ILog> { consoleLogger, capturingLogger }; var multipleLogger = new Common.Logging.MultipleLogger.MultiLogger(allLoggers); Bind <ILog>().ToConstant(multipleLogger); }
public async Task MinInt256() { var capturingLoggerAdapter = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = capturingLoggerAdapter; var web3 = GetWeb3(); var deploymentReceipt = await web3.Eth.GetContractDeploymentHandler <TestDeployment>() .SendRequestAndWaitForReceiptAsync().ConfigureAwait(false); var contractHandler = web3.Eth.GetContractHandler(deploymentReceipt.ContractAddress); var result = await contractHandler.QueryAsync <MinInt256Function, BigInteger>().ConfigureAwait(false); Assert.Equal(result, BigInteger.Parse("-57896044618658097711785492504343953926634992332820282019728792003956564819968")); Assert.Equal("RPC Response: 0x8000000000000000000000000000000000000000000000000000000000000000", capturingLoggerAdapter.LastEvent.MessageObject.ToString()); }
public async Task UMaxInt256() { var capturingLoggerAdapter = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = capturingLoggerAdapter; var web3 = GetWeb3(); var deploymentReceipt = await web3.Eth.GetContractDeploymentHandler <TestDeployment>() .SendRequestAndWaitForReceiptAsync().ConfigureAwait(false); var contractHandler = web3.Eth.GetContractHandler(deploymentReceipt.ContractAddress); var result = await contractHandler.QueryAsync <MaxFunction, BigInteger>().ConfigureAwait(false); Assert.Equal("RPC Response: 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", capturingLoggerAdapter.LastEvent.MessageObject.ToString()); Assert.Equal(result, BigInteger.Parse("115792089237316195423570985008687907853269984665640564039457584007913129639935")); }
public void RoutesToCommonLogging() { // configure for capturing CapturingLoggerFactoryAdapter adapter = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = adapter; var configuration = new LoggerConfiguration().ReadFrom.AppSettings().Enrich.WithProperty("Common.Logging.Type", typeof(CommonLoggingSerilogTests).FullName); var logger = configuration.CreateLogger(); var exception = new Exception(); adapter.ClearLastEvent(); var position = new { Latitude = 25, Longitude = 134 }; var elapsedMs = 34; logger.Error(exception, "Processed {@Position} in {Elapsed:000} ms.", position, elapsedMs); Assert.AreEqual(typeof(CommonLoggingSerilogTests).FullName, adapter.LastEvent.Source.Name); Assert.AreEqual("Processed { Latitude: 25, Longitude: 134 } in 034 ms.", adapter.LastEvent.RenderedMessage); Assert.AreSame(exception, adapter.LastEvent.Exception); }
public void RedirectsToCommonLogging() { CapturingLoggerFactoryAdapter testLoggerFactoryAdapter = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = testLoggerFactoryAdapter; // force entlib logging init Logger.SetLogWriter(new LogWriterFactory().Create()); Logger.Write("init"); // ensure external configuration didn't change LogEntry logEntry = new LogEntry(); logEntry.Categories.Add("mycategory"); logEntry.Message = "testmessage"; // Change to EL 6 (no longer uses Unity) so need to get listener via LogWriter var allEventsSource = Logger.Writer.GetMatchingTraceSources(logEntry).First(source => "All Events".Equals(source.Name)); var listener = (CommonLoggingEntlibTraceListener)allEventsSource.Listeners.First(l => l is CommonLoggingEntlibTraceListener); Assert.IsTrue(listener.Name.StartsWith("Test Capturing Listener")); ILogFormatter formatter = listener.Formatter; string s = formatter.Format(logEntry); Assert.AreEqual("Category: mycategory, Message: testmessage", s); // note that output depends on the formatter configured for the entlib listener! Logger.Write("message1"); Assert.AreEqual("Category: General, Message: message1", testLoggerFactoryAdapter.LastEvent.RenderedMessage); Assert.AreEqual(LogLevel.Info, testLoggerFactoryAdapter.LastEvent.Level); Logger.Write("message2", "custom category", -1, -1, TraceEventType.Warning); Assert.AreEqual("Category: custom category, Message: message2", testLoggerFactoryAdapter.LastEvent.RenderedMessage); Assert.AreEqual("Test Capturing Listener/All Events", testLoggerFactoryAdapter.LastEvent.Source.Name); Assert.AreEqual(LogLevel.Warn, testLoggerFactoryAdapter.LastEvent.Level); }
public void RoutesToCommonLogging() { LoggingConfiguration cfg = new LoggingConfiguration(); CommonLoggingTarget target = new CommonLoggingTarget("${level:uppercase=true}|${logger}|${message}"); cfg.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, target)); NLogLogManager.Configuration = cfg; // configure for capturing CapturingLoggerFactoryAdapter adapter = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = adapter; string msg = "testmessage"; Exception ex = new Exception("testexception"); adapter.ClearLastEvent(); NLogLogManager.GetLogger("myLogger").DebugException(msg, ex); Assert.AreEqual("myLogger", adapter.LastEvent.Source.Name); Assert.AreEqual(string.Format("DEBUG|myLogger|{0}", msg), adapter.LastEvent.RenderedMessage); Assert.AreSame(ex, adapter.LastEvent.Exception); }
public CapturingLogger(CapturingLoggerFactoryAdapter owner, string logName) : base(logName, LogLevel.All, true, true, true, null) { ArgUtils.AssertNotNull("owner", owner); Owner = owner; }
public RecieverFailure() { adapter = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = adapter; }
private void Init() { adapter = LogManager.Adapter as CapturingLoggerFactoryAdapter; adapter.Clear(); }
public PersonSeederController(ISeedCoordinator seedCoordinator, CapturingLoggerFactoryAdapter capturingLoggerAdapter) { _seedCoordinator = seedCoordinator; _capturingLoggerAdapter = capturingLoggerAdapter; }
public TestLogger() { _loggingAdapter = new CapturingLoggerFactoryAdapter(); _loggingAdapter.Clear(); }
public When_transaction_rolled_back_nested_transactions_fail() { adapter = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = adapter; }