コード例 #1
0
        private static void InspectDll(string assemblyPath, IPluginLibrary library)
        {
            try
            {
                var assembly = Assembly.LoadFrom(assemblyPath);
                foreach (var assemblyInspector in _assemblyInspectors)
                {
                    var plugins = new List <IPluginDescriptor>();
                    try
                    {
                        plugins = assemblyInspector.InspectAssembly(assembly);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"{assemblyInspector.GetType().Name} failed to inpect assembly at {assemblyPath}", ex);
                    }

                    foreach (var plugin in plugins)
                    {
                        library.Add(plugin);
                        _logger.Log($"Loaded {plugin.Metadata.Type} '{plugin.Metadata.DisplayName}' from {assemblyPath}");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to load assembly at {assemblyPath}", ex);
            }
        }
コード例 #2
0
 public static async Task Writing(this ICoreLogger logger, int taskId, int maxTime)
 {
     await Task.Run(() =>
     {
         for (int i = 0; i < maxTime; i++)
         {
             logger.Log(new Log("Test", "Test Task", "Test Message"));
         }
     });
 }
        public DurationLogHelper(
            ICoreLogger logger,
            string measuredBlockName,
            LogLevel logLevel = LogLevel.Verbose)
        {
            _logger            = logger;
            _measuredBlockName = measuredBlockName;
            _logLevel          = logLevel;
            _stopwatch         = Stopwatch.StartNew();

            logger.Log(logLevel, null, $"Starting {measuredBlockName}");
        }
コード例 #4
0
 public IActionResult IsExistdriver([FromBody] string phoneNumber)
 {
     try
     {
         bool state = CheckExistdriver(phoneNumber);
         return(Ok(new ResultContract <bool>()
         {
             statuse = true, Data = state
         }));
     }
     catch (Exception ex)
     {
         _logger.Log(HttpContext, ex);
         return(Ok(new ResultContract <string>()
         {
             statuse = false, message = "مشکلی بوجود آمد"
         }));
     }
 }
        public void Log(ICoreLogger logger, LogLevel logLevel)
        {
            if (logger.IsLoggingEnabled(logLevel))
            {
                StringBuilder withPii    = new StringBuilder();
                StringBuilder withoutPii = new StringBuilder();

                withPii.AppendLine($"{Environment.NewLine}[MsalTokenResponse]");
                withPii.AppendLine($"Error: {Error}");
                withPii.AppendLine($"ErrorDescription: {ErrorDescription}");
                withPii.AppendLine($"Scopes: {Scope} ");
                withPii.AppendLine($"ExpiresIn: {ExpiresIn}");
                withPii.AppendLine($"RefreshIn: {RefreshIn}");
                withPii.AppendLine($"AccessToken returned: {!string.IsNullOrEmpty(AccessToken)}");
                withPii.AppendLine($"AccessToken Type: {TokenType}");
                withPii.AppendLine($"RefreshToken returned: {!string.IsNullOrEmpty(RefreshToken)}");
                withPii.AppendLine($"IdToken returned: {!string.IsNullOrEmpty(IdToken)}");
                withPii.AppendLine($"ClientInfo: {ClientInfo}");
                withPii.AppendLine($"FamilyId: {FamilyId}");
                withPii.AppendLine($"WamAccountId exists: {!string.IsNullOrEmpty(WamAccountId)}");

                withoutPii.AppendLine($"{Environment.NewLine}[MsalTokenResponse]");
                withoutPii.AppendLine($"Error: {Error}");
                withoutPii.AppendLine($"ErrorDescription: {ErrorDescription}");
                withoutPii.AppendLine($"Scopes: {Scope} ");
                withoutPii.AppendLine($"ExpiresIn: {ExpiresIn}");
                withoutPii.AppendLine($"RefreshIn: {RefreshIn}");
                withoutPii.AppendLine($"AccessToken returned: {!string.IsNullOrEmpty(AccessToken)}");
                withoutPii.AppendLine($"AccessToken Type: {TokenType}");
                withoutPii.AppendLine($"RefreshToken returned: {!string.IsNullOrEmpty(RefreshToken)}");
                withoutPii.AppendLine($"IdToken returned: {!string.IsNullOrEmpty(IdToken)}");
                withoutPii.AppendLine($"ClientInfo returned: {!string.IsNullOrEmpty(ClientInfo)}");
                withoutPii.AppendLine($"FamilyId: {FamilyId}");
                withoutPii.AppendLine($"WamAccountId exists: {!string.IsNullOrEmpty(WamAccountId)}");

                logger.Log(logLevel, withPii.ToString(), withoutPii.ToString());
            }
        }
コード例 #6
0
        public IActionResult Error()
        {
            string ExceptionMessage = "";
            var exceptionHandlerPathFeature =
    HttpContext.Features.Get<IExceptionHandlerPathFeature>();

            if (exceptionHandlerPathFeature?.Error is FileNotFoundException)
            {
                ExceptionMessage = "File error thrown";
            }
            if (exceptionHandlerPathFeature?.Path == "/index")
            {
                ExceptionMessage += " from home page";
            }
            CoreLog log = new CoreLog()
            {
                ErrorMessage = ExceptionMessage,
                DateTime = DateTime.Now,
                RequsetPath = exceptionHandlerPathFeature?.Path,
            };
            _logger.Log(log);
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
 public void Dispose()
 {
     _logger.Log(_logLevel, null, $"Finished {_measuredBlockName} in {_stopwatch.ElapsedMilliseconds} ms");
 }