12 using System.Collections.Generic;
13 using System.ComponentModel;
15 using System.Runtime.InteropServices;
16 using System.Security.Principal;
45 private FileAttributes fileAttributes = FileAttributes.Normal;
47 private FilterAPI.EVENTTYPE type = FilterAPI.EVENTTYPE.NONE;
49 private DateTime timestamp = DateTime.Now;
51 private string resource =
string.Empty;
53 private string user =
string.Empty;
55 private string process =
string.Empty;
59 private string description =
string.Empty;
68 FileAttributes _fileAttributes,
69 FilterAPI.EVENTTYPE _type,
75 this.process = _process;
76 this.resource = _fileName;
77 this.fileAttributes = _fileAttributes;
79 this.timestamp = _timestamp;
80 this.result = _result;
81 this.description = _description;
91 return fileAttributes;
96 fileAttributes = value;
103 public FilterAPI.EVENTTYPE
Type 215 public static class FileEventHandler
218 static Assembly assembly =
System.Reflection.Assembly.GetEntryAssembly();
219 static string assemblyPath = Path.GetDirectoryName(assembly.Location);
223 static string logFileName = Path.Combine(assemblyPath, filterMessageLogName);
224 static string logFolder = Path.GetDirectoryName(logFileName);
226 static FileEventHandler()
228 if (!Directory.Exists(logFolder))
230 Directory.CreateDirectory(logFolder);
237 private static string GetLogMessage(
FileEvent fileEvent)
239 string retVal =
string.Empty;
241 string fileType =
"FILE";
243 if ((fileEvent.
Attributes & FileAttributes.Directory) == FileAttributes.Directory)
245 fileType =
"DIRECTORY";
249 foreach (FilterAPI.EVENTTYPE type in Enum.GetValues(typeof(FilterAPI.EVENTTYPE)))
251 if ((fileEvent.
Type & type) == type && type != FilterAPI.EVENTTYPE.NONE )
253 if (eventType.Length > 0)
255 eventType = eventType +
',' + type.ToString();
259 eventType = type.ToString();
267 retVal = fileEvent.
Resource +
"|" + fileType +
"|" + fileEvent.
Timestamp.ToString(
"yyyy-MM-ddTHH:mm:ss") +
"|";
268 retVal += eventType +
"|" + fileEvent.
Result.ToString() +
"|" + fileEvent.
Process +
"|";
275 public static void LogFileEvent(
FileEvent fileEvent)
279 string logMessage = GetLogMessage(fileEvent);
281 if (logMessage.Trim().Length > 0)
283 if (
File.Exists(logFileName))
285 FileInfo fileInfo =
new FileInfo(logFileName);
289 File.Delete(logFileName +
".bak");
290 File.Move(logFileName, logFileName +
".bak");
294 File.AppendAllText(logFileName, logMessage +
"\r\n");
299 EventManager.WriteMessage(172,
"LogTrasaction",
EventLevel.Error,
"Log filter message failed with error " + ex.Message);
string Process
The process name
string Resource
Full path of the file name
FilterAPI.EVENTTYPE Type
type of the event -can be an enum
FileAttributes Attributes
the file attributes
DateTime Timestamp
// timestamp of event
FileEvent(string _user, string _process, string _fileName, FileAttributes _fileAttributes, FilterAPI.EVENTTYPE _type, DateTime _timestamp, FileEventResult _result, string _description)
FileEventResult Result
The status of the result
string Description
The description of the IO
static string FilterMessageLogName
static long FilterMessageLogFileSize