我想创建一个目标,清除特定文件夹中7天以前的日志文件.当我尝试在文件集中放入"日期"元素时,我收到错误.我怎么能这样做?
<delete>
fileset basedir="${StageIISRoot}/MySite/App_Data/ErrorLog">
<date datetime="${datetime::now() - timespan::from-days(7)}" when="before"/>
<include name="*.xml" />
</fileset>
</delete>
Run Code Online (Sandbox Code Playgroud) 我有一个读取和写入的文件.我需要确保在写入时,没有其他人会尝试写入它.
我对整个函数进行了锁定,允许读取或写入,但仍然会出现错误,例如进程无法访问文件'FILENAME',因为它正由另一个进程使用.
public static TYPE Property{
get{
data mydata;
Object obj = new object();
Monitor.Enter(obj);
// check if data has not changed
// if it has not, just read
using (Stream stream = File.Open(fileLocation, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
//....
}
// else, if data changed, then need to write to file to save the new data
using (Stream stream = File.Open(fileLocation, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read)) {
BinaryFormatter bf = new BinaryFormatter();
try {
bf.Serialize(stream, (data);
}
//DONE processing
Monitor.Pulse(obj);
Monitor.Exit(obj);
return …Run Code Online (Sandbox Code Playgroud)