Paste the below into the router/switch. (Always verify these exist first by doing them manually then if they work for you for that model of device, then you can just copy paste on devices you know it works on.)
service sequence-numbers
service timestamps debug datetime localtime msec
logging buffered 10000000 debug
no logging console
no logging monitor
default logging rate-limit
default logging queue-limit
<Enable debugs, then wait for issue to occur.>
..
<Enable session capture to txt file in terminal program.>
Router# terminal length 0
Router# show logging
Recommended materials
https://community.cisco.com/t5/collaboration-knowledge-base/how-to-properly-and-safely-collect-debugs-on-an-ios-router/ta-p/3114693
Comments