Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to add the current date to my log file name as Log20210817.txt I am using c# app and if an error occurred then output the log file with current date.

What I have tried:

XML
<configuration>
<appSettings>
  <add key="logPath" value="C:\Temp\log"current dateTime".txt" />
</appSettings>
</configuration>
Posted
Updated 17-Aug-21 3:44am
v2

1 solution

You could make the logPath field into a format string like:
XML
<add key="logPath" value="C:\Temp\log{0}.txt" />

Then you just need something like:
C#
string logPath = // the key from the XML
string fullPath = string.Format(logPath, DateTime.Now.ToString("yyyyMMdd"));
 
Share this answer
 

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