Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Guys for example I create log file and I want to delete them once a hour or once o week. How can I do ?

What I have tried:

.............................................
Posted
Updated 22-Jun-20 5:08am
v2
Comments
Richard MacCutchan 22-Jun-20 10:26am    
What do you mean? What is the timer supposed to do?
Member 14769019 22-Jun-20 10:28am    
Sorry I guess I couldn't tell. For example I created log file and I want to delete them once a hour or once a week.
F-ES Sitecore 22-Jun-20 10:59am    
use log4net, it has that functionality built-in.
PIEBALDconsult 22-Jun-20 11:04am    
Windows Scheduled Task and a DEL command.

I've been writing code for over 40 years, so do with this as you see fit...

If it were me, I'd write a windows service that lives on the web server to do this.

Of course, if it were me, I'd put log entries into a database (instead of cluttering up the files system on the web server), and then schedule a job that runs once per day and deletes entries older than a certain number of days.

But that's just me.
 
Share this answer
 
v2
Comments
MadMyche 22-Jun-20 11:10am    
+5. Similar to what I have implemented, which runs daily; adding the logs to a month.zip file and then deleting the original log
If it were me, I'd write up a command line to do it from a Windows Scheduler job. No need to write up any code at all.
 
Share this answer
 
C#
System.Threading.Thread t = new System.Threading.Thread(() => {
    System.Threading.Thread.Sleep(100000);
    System.IO.File.Delete(path);
});

t.Start();


It's not 100% robust though and goes without saying that "path" has to be a path on the server, you can't delete client-side files. Also haven't tried this with core but according to the docs it should still work.
 
Share this answer
 
Comments
F-ES Sitecore 22-Jun-20 11:00am    
Just so people know, the OP has completely changed the question so this answer now seems irrelevant.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900