title: How to inject logger in an extended class (XClass) in Typo3?
body: <p>I want to extend the \TYPO3\CMS\Backend\Controller\NewRecordController in Typo3 and log something to the logging system. The Logging section in Typo3 help says that I should instantiate the logger by injecting LoggerInterface to the constructor of my class. So my code is something like this:</p>
  <pre><code>&lt;?php
  
  namespace Vendor\Project\Xclass;
  use Psr\Log\LoggerInterface;
  use Psr\Http\Message\ServerRequestInterface;
  
  
  class NewRecordController extends \TYPO3\CMS\Backend\Controller\NewRecordController
  {
      private LoggerInterface $logger;
      
      public function __construct(LoggerInterface $logger)
      {
          $this-&gt;logger = $logger;
      }
  
      protected function renderNewRecordControls(ServerRequestInterface $request): void
      {
          $this-&gt;logger-&gt;warning('test');
      }
  }
  </code></pre>
  <p>When I run the code (add a new record in Typo3 BE) I get <strong>ArgumentCountError</strong> error.</p>
  <p>I tried setting <em>public:true</em> in <em>services.yaml</em> provided in the third link below, but now lock.</p>
  <p>How can I fix this?</p>
  <p><a href="https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Logging/Logger/Index.html" rel="nofollow noreferrer">https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Logging/Logger/Index.html</a></p>
  <p><a href="https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Xclasses/Index.html#" rel="nofollow noreferrer">https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Xclasses/Index.html#</a></p>
  <p><a href="https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/DependencyInjection/Index.html" rel="nofollow noreferrer">https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/DependencyInjection/Index.html</a></p>
  <p>PS.</p>
  <p>It seems that the problem exists even in the case I'm not extending an interface. To test this, I tried to implement the event listener 'AfterFileAddedEvent', and I still get the same error. My code is mentioned below:</p>
  <p>ManuscriptAdded.php</p>
  <pre><code>&lt;?php
  
  namespace Vendor\Project\EventListener;
  use TYPO3\CMS\Core\Resource\Event\AfterFileAddedEvent;
  use Psr\Log\LoggerInterface;
  
  class ManuscriptAdded
  {
      private LoggerInterface $logger;
  
      public function __construct(LogerInterface $logger)
      {
          $this-&gt;logger = $logger;
      }
  
      public function __invoke(AfterFileAddedEvent $event): void
      {
          $this-&gt;logger-&gt;critical('testtest');
      }
  }
  
  ?&gt;
  </code></pre>
  <p>Services.yaml:</p>
  <pre><code>services:
    _defaults:
      autowire: true
      autoconfigure: true
      public: true
      
    Vendor\Project\EventListener\ManuscriptAdded:
      tags:
        - name: event.listener
          identifier: 'msAdded'
          event: TYPO3\CMS\Core\Resource\Event\AfterFileAddedEvent
  </code></pre>