ULS Logs Not Consistently Being Written to Usage Database

SharePoint gives you the option to write ULS logs to the Usage database. In order for this to work, your farm must have a 'Usage and Health Data Collection Service' Application running. You can enable this by going into Central Administration - Monitoring - Configure usage and health data collection - Enable usage data collection.

To log ULS logs to this database you must enable the 'Diagnostic Data Provider: Trace Log' timer job. By default, this job runs every 10 minutes and logs current ULS to one of 31 dbo.ULSTraceLog_Partition tabbles in the Usage database. There is one partition for each day of the month and every day at midnight, it will start logging to the next partition. By default, logs are only stored for 14 days, so only 14 partition tables should ever have data in it. This number is configurable.

There is also a configurable number which determines how large those partitions can grow. You can find this under the dbo.Configuration table in the Usage database under the property 'Max Total Bytes - ULSTraceLog'. If you take this number, and divide it by 'Retention Period - ULSTraceLog' (also found in dbo.Configuration), this is how many bytes each partition can grow. Taking the default values of 6200000000 for Max Total Bytes and 14 for Retention period, this only gives you 5.77GB worth of logs each day. This may be fine for a small-mid size farm, but for a large farm, this will probably need to be increased. If you are running out of space, you will find that the ULS logs are being written to the partitions correctly starting at midnight and are stopping some point throughout the day. To resolve this, either raise the value of 'Max Total Bytes - ULSTraceLog', lower the value of  'Retention Period - ULSTraceLog', or some combination of the two.

Hope this saves you some time!