Windows service not working

I have a windows service program which run periodically and creates some xml files for tables in my database.
Sometimes service gets stopped automatically when creating xml file.
It is not returning any log, just a xml file get created with size 0 kb. so i think problem occurs while saving xml file.
But not getting what causing the issue. Can anyone help me to fix this?

Well just as rough guess: In most cases file priviledges are the culprit. In which context does your service run? Create a CLI version of your service with remote debugging enabled if possible. Use EventLogging and print your steps (Loop entered, Method started etc) into Windows Event Log to see where your App crashes.