He was born in Glasgow on 19 April 1834, the son of Agnes (1796–1874) and Hugh Trayner (1798–1861). He studied law first at the University of Glasgow and then at University of Edinburgh
In February 1885, he was elected a Senator of the College of Justice.[1] In 1886, he was awarded an honorary doctorate (LLD) by the University of Glasgow. At this time he was living at 27 Moray Place in Edinburgh''''''''s West End.
In the 1901, census he was living at The Grange in North Berwick and was being visited by his friend and colleague Sir John Cheyne and his wife Lady Cheyne.
He died at Dean House in Edinburgh on 3 February 1929 and is buried in Dean Cemetery. He shares the grave of his son-in-law, Edward Theodore Salvesen, in the new Lords Row against the north wall of the 20th century extension to the cemetery, backing onto Queensferry Road. The memorial was designed by Sir Robert Lorimer.