The colloquial word moonlighting (from 1954, originally U.S., moonlighter for the person doing it) for a secondary paid work (often at night) in addition to one's regular job is a given per current usage and dictionaries; however, the origin and the history of the word can give us a glare of its multifarious semantic development, helping us to make sense of the current meaning.
In fact, the current usage is a positive semantic shift (amelioration) as an analogy to its origin, illicit activities done at night (under the moonlight). The sense 'illicit activity' is apparently still there as OED adds that this usage is rare, possibly used in Irish English only, in some isolated cases. Here is the earlier second sense of moonlighting (from 1882) from OED:
The performance of an illicit action by night; (Irish History) the perpetration by night of raids on tenants who incurred the hostility of the Land League. Also figurative. Now rare.
Although, the earliest illicit activity sense, which is still in use, is moonlight flit; from 1824, defined in OED as:
n. the act of leaving one's accommodation without paying the rent; the removal of household goods by night to avoid paying rent; (hence) a hurried departure or escape by night.
However, OED also has moonlight flitting from as early as 1721.
n. Scottish (now rare) = moonlight flit n.
There is even a rare usage of moonlight (n.) meaning moonshine (.n) ('smuggled or illicitly distilled alcoholic liquor'), from 1809, according to OED; but adds that it is British regional.
Interestingly, there is an uncommon colloquial word sunlighting also (which I haven't heard before but found while searching), coined after moonlighting; from 1961, defined in OED as:
colloquial. The practice of having a second job in addition to one's regular employment, which is undertaken during the day (rather than at night).
Additional history:
There is also the earliest sense of the noun moonlighting listed in OED, from 1880, which appears to be originated independently in Australian English; defined in OED as:
Australian. The practice of mustering wild cattle at night.
In Australia, in old times, there was the practice of moonlighting, where they mustered wild cattle at night because they would come into clearing to graze at night and the stockmen needed sufficient moonlight to be able to see at night. Mustering is the act of collecting together wild cattle by riding round a scattered herd and driving it together. I've also found an Australian language book (by Sidney John Baker) talking about moonlighting as a method of mustering scrubbers (wild cattle) at night; and even as the shooting of possums seen in the tree branches against the light of the moon. The usage was not isolated to just one activity and has extended to other activities done in the moonlight. This tells us that all related senses are an extended sense from the light of the moon, moonlight.