How can dmesg content be logged into a file?

You need to look at either /etc/rsyslog.conf or /etc/syslog.conf. If you have a line early on such as:

*.*                -/var/log/syslog

Everything, including the stuff from dmesg, should go to that file. To target it better:

kernel.*           -/var/log/dmesg

If that fails for some reason, you could periodically (e.g. via cron):

dmesg > /var/log/dmesg

Depending on how big the dmesg buffer is (this is compiled into the kernel, or set via the log_buf_len parameter) and how long your system has been up, that will keep a record of the kernel log since it started.

If you want to write the dmesg output continuously to a file use the -w (--follow) flag.

dmesg --follow > mydmesg.log

If you use systemd then you can get all the information from the systemd journal using journalctl -k. syslog and rsyslog are not necessary if you use systemd.