public void Log_Verbose_EmitsExpectedEvent()
        {
            string eventName            = string.Empty;
            string details              = string.Empty;
            string summary              = "TestMessage";
            string functionInvocationId = string.Empty;
            string activityId           = string.Empty;

            _mockEventGenerator.Setup(p => p.LogFunctionTraceEvent(LogLevel.Debug, _subscriptionId, _websiteName, _functionName, eventName, _category, details, summary, string.Empty, string.Empty, functionInvocationId, _hostInstanceId, activityId));

            _logger.LogDebug(summary);

            _mockEventGenerator.VerifyAll();
        }
示例#2
0
        static void Main(string[] args)
        {
            ILoggerManager loggerManager = new LoggerManager();

            Dictionary <string, object> settings = new Dictionary <string, object>();

            settings.Add("Log4Net.ConversionPattern", "%date [%thread] %-5level %logger - %message%newline");
            settings.Add("Log4Net.MaximumFileSize", "1MB");
            settings.Add("Log4Net.MaxSizeRollBackups", 5);
            settings.Add("Log4Net.File", @"d:\Log4NetLogger.txt");

            ILogger log4NetLogger = new Log4NetLogger("Log4NetLogger");

            log4NetLogger.Configure(settings);
            loggerManager.AddLogger("Log4NetLogger", log4NetLogger);

            ILogger eventLogLogger = new EventLogLogger("TestApp", "Application", 400, null);

            loggerManager.AddLogger("EventLogLogger", eventLogLogger);

            SystemLogger systemLogger = new SystemLogger(loggerManager);

            systemLogger.LogInfo("This is my first info log.");
            systemLogger.LogDebug("This is my first debug log.");
            systemLogger.LogWarning("This is my first warning log.");
            systemLogger.LogError(ErrorSeverity.Low, "This is my first low error log.", new Exception("This is my first low error log."));
            systemLogger.LogError(ErrorSeverity.Medium, "This is my first medium error log.", new Exception("This is my first medium error log."));
            systemLogger.LogError(ErrorSeverity.High, "This is my first high error log.", new Exception("This is my first high error log."));
            systemLogger.LogError(ErrorSeverity.Extreme, "This is my first extreme error log.", new Exception("This is my first extreme error log."));
            systemLogger.LogMethodStart("static void Main(string[] args)", new string[] { "args" }, new object[] { args });
            systemLogger.LogMethodEnd("static void Main(string[] args)", true);
            systemLogger.LogMethodEnd("static void Main(string[] args)", false);
        }
        public void Log_Ignores_FunctionUserCategory()
        {
            // Create a logger with the Function.{FunctionName}.User category, which is what determines user logs.
            ILogger logger = new SystemLogger(Guid.NewGuid().ToString(), LogCategories.CreateFunctionUserCategory(_functionName), _mockEventGenerator.Object, new TestEnvironment(), _debugStateProvider.Object, null);

            logger.LogDebug("TestMessage");

            // Make sure it's never been called.
            _mockEventGenerator.Verify(p => p.LogFunctionTraceEvent(It.IsAny <LogLevel>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), string.Empty, string.Empty, string.Empty, string.Empty, string.Empty), Times.Never);
        }
示例#4
0
        public void Log_UsesScopeFunctionName_IfNoCategory(string key)
        {
            var logScope = new Dictionary <string, object>
            {
                [key] = "TestFunction3"
            };

            var logger = new SystemLogger(_hostInstanceId, "Not.A.Function", _mockEventGenerator.Object, _environment, _debugStateProvider.Object, null, new LoggerExternalScopeProvider());

            _mockEventGenerator.Setup(p => p.LogFunctionTraceEvent(LogLevel.Debug, It.IsAny <string>(), It.IsAny <string>(), "TestFunction3", It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()));

            using (logger.BeginScope(logScope))
            {
                logger.LogDebug("TestMessage");
            }
        }