Hi, try following Logger. Unfortunately, it is impossible for me to insert code into this buggy forum UI.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I need a tool that creates log files for me without blocking the application should be done in parallel.
Furthermore I need to be able to store the log file in this format. <NameOfApplication><YYYY-MM-dd>.log
If the size exceeds 50MByte a new file should be written. After 15 days, they should be deleted automatically.
Are there FreeTools for these requirements? Does anyone have a good sample code for C#, WPF, VS2017? Thanks in advance.
Regards Markus
Hi, try following Logger. Unfortunately, it is impossible for me to insert code into this buggy forum UI.
You can use Task Scheduler to delete the file automatically.
First you need to create a simple project which use to delete the files only include the below method, build the project to get the exe.
public static void DelectDir(string srcPath)
{
try
{
DirectoryInfo dir = new DirectoryInfo(srcPath);
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();
foreach (FileSystemInfo i in fileinfo)
{
TimeSpan timeSpan = System.DateTime.Now- i.LastWriteTime;
if (timeSpan.TotalSeconds>15*24*3600 ) //delete the files before 15 days
{
File.Delete(i.FullName);
}
}
}
catch (Exception e)
{
throw;
}
}
Then you need to create a task Scheduler to run this exe. The step is :
You also use a logging framework like serilog which lets you set the max number of days to keep a file and set max file size
Hi Markus, I use a simple Logger like this:
Hi Peter,
App run continuously!
App start only once per day or week. The best one time for month without error.
Yes only if we restart the application we shoukd check the days, for example 14 (Configuration value)
I have to be able to open and view the log file at all times, e.g. with Notepad++.
Checking whether more than 50 MB is enough for one check per hour.
Regards Markus and Thanks in advance.