public static class ErrorCenter
{
private static EventLog log = new EventLog("PipeMap");
public static void WriteInError(string ErrorMessage, string eventSource, int rowIndex)
{ if (!EventLog.SourceExists("PipeMap"))
EventLog.CreateEventSource(eventSource, "PipeMap");
try
{
log.Source = eventSource;
log.WriteEntry(ErrorMessage, EventLogEntryType.Warning, rowIndex);
}
catch (System.IO.FileNotFoundException exception)
{
log.WriteEntry("写入日志出错" + exception.Message, EventLogEntryType.Error);
} }
public static Boolean HasWarringError(string eventSource)
{
List<EventLogEntry> entryList = new List<EventLogEntry>();
foreach (EventLogEntry entry in log.Entries)
{
if (entry.Source == eventSource && entry.EntryType == EventLogEntryType.Warning)
{
entryList.Add(entry);
}
}
if (entryList.Count == 0)
{
return true;
}
else
{
return false;
}
}
public static void DeleteError(string eventSource, int rowIndex)
{
foreach (EventLogEntry entry in log.Entries)
{
if (entry.Source == eventSource)
{
if (entry.EventID == rowIndex)
{
entry.Dispose();
}
}
} }
}上边是我操作日志的源码,但是我把他们注释掉,还原原来的样子,我的Dll还是不能加载
Error:未能加载文件或程序集“我的Dll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。拒绝访问。
[DllImport("ErrorCenter.dll")]
public static extern string WriteInError(string s,string s1,int i);