本文整理汇总了C#中System.Diagnostics.EventLog类的典型用法代码示例。如果您正苦于以下问题:C# EventLog类的具体用法?C# EventLog怎么用?C# EventLog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventLog类属于System.Diagnostics命名空间,在下文中一共展示了EventLog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
static public ImageProcessingResult Process(string imageName, IBinaryRepository binaryRepository)
{
var log = new EventLog("Application")
{
Source = "Tadmap"
};
log.WriteEntry("Processing image:" + imageName, EventLogEntryType.Information);
Stream binary = binaryRepository.GetBinary(imageName);
if (binary == null)
{
log.WriteEntry("No binary found:" + imageName, EventLogEntryType.Warning);
return new ImageProcessingResult { Key = imageName, Result = ImageProcessingResult.ResultType.Failed }; // Image not available in the queue yet.
}
// If I have an image I should renew the message.
IImageSet imageSet = new ImageSet1(imageName);
int zoomLevels;
int tileSize;
imageSet.Create(binary, binaryRepository, out zoomLevels, out tileSize);
log.WriteEntry("Processing finished.", EventLogEntryType.Information);
return new ImageProcessingResult
{
Key = imageName,
Result = ImageProcessingResult.ResultType.Complete,
ZoomLevel = zoomLevels,
TileSize = tileSize
};
}
示例2: WriteLog
private static void WriteLog(TraceLevel level, String messageText)
{
try
{
EventLogEntryType LogEntryType;
switch (level)
{
case TraceLevel.Error:
LogEntryType = EventLogEntryType.Error;
break;
default:
LogEntryType = EventLogEntryType.Error;
break;
}
String LogName = "Application";
if (!EventLog.SourceExists(LogName))
{
EventLog.CreateEventSource(LogName, "BIZ");
}
EventLog eventLog = new EventLog(LogName, ".", LogName);//��־���ԵĻ���
eventLog.WriteEntry(messageText, LogEntryType);
}
catch
{
}
}
示例3: EventViewerLogger
/// <summary>
/// The constructor.
/// </summary>
/// <param name="source">The source name by which the application is registered on the local computer.</param>
/// <param name="logName">The name of the log the source's entries are written to.</param>
public EventViewerLogger(string source, string logName)
{
// Sanitize
if (string.IsNullOrWhiteSpace(source))
{
throw new ArgumentException("cannot be null, empty, or white space", "source");
}
if (string.IsNullOrWhiteSpace(logName))
{
throw new ArgumentException("cannot be null, empty, or white space", "logName");
}
// Attempt to ensure that the event log source exists
try
{
if (!EventLog.SourceExists(source))
{
EventLog.CreateEventSource(source, logName);
}
}
catch (SecurityException)
{
// Ignore it...
}
// Initialize the event log for logging
_eventLog = new EventLog
{
Source = source,
Log = logName
};
}
示例4: CanGetCountFromEventLog
public void CanGetCountFromEventLog()
{
using (EventLog eventLog = new EventLog("Application"))
{
Assert.IsTrue(eventLog.Entries.Count > 0);
}
}
示例5: AddWindowsEventLog
private void AddWindowsEventLog(string message, EventLogEntryType logType = EventLogEntryType.Information, string moduleName = "", int codeErreur = 0, bool fromFileLogEvent = false)
{
EventLog evLog = new EventLog(Const.WINDOWS_LOG_NAME);
message = string.Concat(message, "\r\n", "Module : ", moduleName);
evLog.Source = Const.DEFAULT_APPLICATION_NAME;
InitWindowsEventLog();
try
{
evLog.WriteEntry(message, logType, codeErreur);
}
catch (Exception ex)
{
if (!fromFileLogEvent)
{
AddFileEventLog("Impossible d'écrire dans le journal de log " + Log.Const.WINDOWS_LOG_NAME + ".\r\nLe journal doit être créé préalablement avec un compte Administrateur.\r\nMessage :\r\n" + message + "\r\nException : " + ex.Message, logType, moduleName, codeErreur, true);
}
}
finally
{
evLog.Close();
}
}
示例6: OnStart
protected override void OnStart(string[] args)
{
if (!EventLog.SourceExists("SSISIncomingDirectoryWatcher", "."))
{
EventLog.CreateEventSource("SSISIncomingDirectoryWatcher", "Application");
}
Lg = new EventLog("Application", ".", "SSISIncomingDirectoryWatcher");
Lg.WriteEntry("Service started at " + DateTime.Now, EventLogEntryType.Information);
try
{
tw = File.CreateText(logFilePath);
tw.WriteLine("Service started at {0}", DateTime.Now);
readInConfigValues();
Watcher = new FileSystemWatcher();
Watcher.Path = dirToWatch;
Watcher.IncludeSubdirectories = false;
Watcher.Created += new FileSystemEventHandler(watcherChange);
Watcher.EnableRaisingEvents = true;
}
catch (Exception ex)
{
Lg.WriteEntry(ex.Message, EventLogEntryType.Error);
}
finally
{
tw.Close();
}
}
示例7: Window_Loaded
private void Window_Loaded(object sender, RoutedEventArgs e)
{
EventLog log = new EventLog("EventLog Log");
log.Source = "LoggingApp";
log.WriteEntry("LoggingApp Started", EventLogEntryType.Information, 1001);
}
示例8: sigConfigServer
public sigConfigServer(String[] args)
{
// Initialise variables and check commandline arguments for values (for manual specific logging)
InitializeComponent();
this.AutoLog = false;
sigConfigServerServiceLog = new System.Diagnostics.EventLog();
string logSource = "sigConfigServerSource";
string logName = "sigConfigServerLog";
if (args.Count() > 0)
{
logSource = args[0];
}
if (args.Count() > 1)
{
logSource = args[1];
}
if (!System.Diagnostics.EventLog.SourceExists(logSource))
{
System.Diagnostics.EventLog.CreateEventSource(logSource, logName);
}
sigConfigServerServiceLog.Source = logSource;
sigConfigServerServiceLog.Log = logName;
// Logging
sigConfigServerServiceLog.WriteEntry("Roswell Email Signature Sync service (server mode) created.");
this.OnStart();
}
示例9: OnStart
protected override void OnStart(string[] args)
{
ConfigurationManager.RefreshSection("AppSetings");
string logSource = ConfigurationManager.AppSettings["LogSource"];
string logName = ConfigurationManager.AppSettings["LogName"];
if (!EventLog.SourceExists(logSource))
{
EventLog.CreateEventSource(logSource, logName);
}
log = new EventLog { Source = logSource };
int port;
if (!int.TryParse(ConfigurationManager.AppSettings["ListenPort"], out port))
{
port = 9999;
}
server = new DashboardServer(port, new PrivateDataSource());
server.Log = new EventLogger { EventLog = log };
server.Start();
}
示例10: OnUnhandledException
void OnUnhandledException(object o, UnhandledExceptionEventArgs e) {
// Let this occur one time for each AppDomain.
if (Interlocked.Exchange(ref _unhandledExceptionCount, 1) != 0)
return;
StringBuilder message = new StringBuilder("\r\n\r\nUnhandledException logged by UnhandledExceptionModule.dll:\r\n\r\nappId=");
string appId = (string) AppDomain.CurrentDomain.GetData(".appId");
if (appId != null) {
message.Append(appId);
}
Exception currentException = null;
for (currentException = (Exception)e.ExceptionObject; currentException != null; currentException = currentException.InnerException) {
message.AppendFormat("\r\n\r\ntype={0}\r\n\r\nmessage={1}\r\n\r\nstack=\r\n{2}\r\n\r\n",
currentException.GetType().FullName,
currentException.Message,
currentException.StackTrace);
}
EventLog Log = new EventLog();
Log.Source = _sourceName;
Log.WriteEntry(message.ToString(), EventLogEntryType.Error);
}
示例11: Main
static void Main()
{
if (!EventLog.SourceExists("SelfMailer"))
{
EventLog.CreateEventSource("SelfMailer", "Mes applications");
}
EventLog eventLog = new EventLog("Mes applications", ".", "SelfMailer");
eventLog.WriteEntry("Mon message", EventLogEntryType.Warning);
BooleanSwitch booleanSwitch = new BooleanSwitch("BooleanSwitch", "Commutateur booléen.");
TraceSwitch traceSwitch = new TraceSwitch("TraceSwitch", "Commutateur complexe.");
TextWriterTraceListener textListener = new TextWriterTraceListener(@".\Trace.txt");
Trace.Listeners.Add(textListener);
Trace.AutoFlush = true;
Trace.WriteLineIf(booleanSwitch.Enabled, "Démarrage de l'application SelfMailer");
Project = new Library.Project();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Forms.Main());
Trace.WriteLineIf(traceSwitch.TraceInfo, "Arrêt de l'application SelfMailer");
}
开发者ID:hugonjerome,项目名称:CSharp-5-Developpez-des-applications-Windows-avec-Visual-Studio-2012,代码行数:25,代码来源:Program.cs
示例12: Logger
/// <summary>
/// Creating an EventSource requires certain permissions, which by default a IIS AppPool user does not have.
/// In this case just ignore security exceptions.
/// In order to make this work, the eventsource needs to be created manually
/// </summary>
public Logger(string name, string source) {
try {
log = new EventLog();
log.Source = source;
}
catch (Exception) { }
}
示例13: ReportProcess
/// <summary>
/// 建構子
/// </summary>
/// <param name="SetProcessFile">處理的檔案</param>
/// <param name="SeteventLog1">事件檢示器物件</param>
public ReportProcess(string SetProcessFile,
EventLog SeteventLog1
)
{
ProcessFile = SetProcessFile;
eventLog1 = SeteventLog1;
}
示例14: TaskSchedulerManager
public TaskSchedulerManager(EventLog el)
{
scheduler = new TaskScheduler.TaskScheduler();
scheduler.Connect(null, null, null, null);
rootFolder = scheduler.GetFolder("\\");
eventLog = el;
}
示例15: SendersManager
public SendersManager()
{
new EventLogPermission(EventLogPermissionAccess.Administer, ".").Demand();
_localLog = new EventLog("Application", ".", "el2slservice");
_senders = new List<SyslogSender>();
_config = new El2SlConfig();
}