This is a known issue in Mojave. There's something wrong with CoreMIDI that causes it to take much longer to initialize than it used to. Logic Pro X has a hard-coded CoreMIDI initialization timeout that expires before CoreMIDI finishes starting, so Logic on High Sierra takes a long time to launch (waiting for CoreMIDI), and then can't use MIDI because the timeout expires.
A good workaround is to initialize CoreMIDI before launching Logic. An easy way to do this is to launch the Audio MIDI Setup utility and open the MIDI Studio window. It will take an unusually long time to load the MIDI studio, but after it has loaded, CoreMIDI will be initialized. Leave that open and launch Logic and it will open up much faster and MIDI will work.
Any other app that initializes CoreMIDI will work also. Advantages of using the Audio MIDI Setup utility is that every Mac has it and it is fairly lightweight, so you leave maximum processing power available for Logic.
Edit: Updating to Catalina also fixes the problem.