本文整理汇总了C#中System.Diagnostics.EventSourceCreationData类的典型用法代码示例。如果您正苦于以下问题:C# EventSourceCreationData类的具体用法?C# EventSourceCreationData怎么用?C# EventSourceCreationData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventSourceCreationData类属于System.Diagnostics命名空间,在下文中一共展示了EventSourceCreationData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateEventSource
public override void CreateEventSource (EventSourceCreationData sourceData)
{
// construct path for storing log entries
string logDir = FindLogStore (sourceData.LogName);
// create event log store (if necessary), and modify access
// permissions (unix only)
if (!Directory.Exists (logDir)) {
// ensure the log name is valid for customer logs
ValidateCustomerLogName (sourceData.LogName, sourceData.MachineName);
Directory.CreateDirectory (logDir);
// MS does not allow an event source to be named after an already
// existing event log. To speed up checking whether a given event
// source already exists (either as a event source or event log)
// we create an event source directory named after the event log.
// This matches what MS does with the registry-based registration.
Directory.CreateDirectory (Path.Combine (logDir, sourceData.LogName));
if (RunningOnUnix) {
ModifyAccessPermissions (logDir, "777");
ModifyAccessPermissions (logDir, "+t");
}
}
// create directory for event source, so we can check if the event
// source already exists
string sourceDir = Path.Combine (logDir, sourceData.Source);
Directory.CreateDirectory (sourceDir);
}
示例2: Run
static void Run()
{
string messageFile = "message.txt";
string myLogName;
string sourceName = "SampleApplicationSource";
// Create the event source if it does not exist.
if (!EventLog.SourceExists(sourceName))
{
// Create a new event source for the custom event log named "myNewLog".
myLogName = "myNewLog";
EventSourceCreationData mySourceData = new EventSourceCreationData(sourceName, myLogName);
// Set the message resource file that the event source references.
// All event resource identifiers correspond to test in this file.
if (!System.IO.File.Exists(messageFile))
{
Console.WriteLine("Input message resource file does not exist - {0}", messageFile);
messageFile = "";
}
else
{
// Set the specified file as the resource file for message text,
// category text, and message parameter strings.
mySourceData.MessageResourceFile = messageFile;
mySourceData.CategoryResourceFile = messageFile;
mySourceData.CategoryCount = CategoryCount;
}
}
}
示例3: CreateEventLog
public static EventLog CreateEventLog(string name)
{
string eventLogName = string.Empty;
try
{
eventLogName = HostingEnvironment.ApplicationVirtualPath.Trim("/".ToCharArray());
if (string.IsNullOrEmpty(eventLogName)) eventLogName = HostingEnvironment.SiteName;
}
catch
{
// not running under a hosted environment
}
if (string.IsNullOrEmpty(eventLogName)) eventLogName = name;
if (string.IsNullOrEmpty(eventLogName)) eventLogName = "SnCore";
if (! EventLog.SourceExists(eventLogName))
{
EventSourceCreationData data = new EventSourceCreationData(eventLogName, "Application");
EventLog.CreateEventSource(data);
}
EventLog result = new EventLog();
result.Log = "Application";
result.Source = eventLogName;
return result;
}
示例4: createEventLogSource_Click
protected void createEventLogSource_Click(object sender, EventArgs e)
{
try
{
EventSourceCreationData creationData = new EventSourceCreationData(_Source, _LogName);
if (EventLog.Exists(_LogName, ".") == false)
{
//source未在该服务器上注册过
EventLog.CreateEventSource(creationData);
createMessage.InnerText = "没有Log,创建Log和Source";
}
else
{
if (EventLog.SourceExists(_Source))
{
string originalLogName = EventLog.LogNameFromSourceName(_Source, ".");
//source注册的日志名称和指定的logName不一致,且不等于source自身
//(事件日志源“System”等于日志名称,不能删除。[System.InvalidOperationException])
if (string.Compare(_LogName, originalLogName, true) != 0 && string.Compare(_Source, originalLogName, true) != 0)
{
//删除现有的关联重新注册
EventLog.DeleteEventSource(_Source, ".");
EventLog.CreateEventSource(creationData);
createMessage.InnerText = "已经有Log,重新创建Log和Source";
}
}
}
}
catch (System.Exception ex)
{
createMessage.InnerText = ex.Message;
}
}
示例5: Init
private bool Init()
{
try
{
if (!EventLog.SourceExists(_eventSourceName))
{
var eventSourceData = new EventSourceCreationData(_eventSourceName, _logName);
EventLog.CreateEventSource(eventSourceData);
}
_DBConnStr = ConfigurationManager.AppSettings["DBConnStr"].Trim();
_MQServerUri = ConfigurationManager.AppSettings["MQServerUri"].Trim();
_QueueName = ConfigurationManager.AppSettings["QueueName"].Trim();
_Interval = int.Parse(ConfigurationManager.AppSettings["Interval"].Trim());
_KpiInterval = int.Parse(ConfigurationManager.AppSettings["KpiInterval"].Trim());
_Timer = new Timer() { Interval = _Interval, AutoReset = true, Enabled = true };
_Timer.Elapsed += new ElapsedEventHandler(SendKpi);
Log("Init completed.");
return true;
}
catch(Exception ex)
{
LogError(ex.Message);
return false;
}
}
示例6: CreateEventSource
public override void CreateEventSource (EventSourceCreationData sourceData)
{
using (RegistryKey eventLogKey = GetEventLogKey (sourceData.MachineName, true)) {
if (eventLogKey == null)
throw new InvalidOperationException ("EventLog registry key is missing.");
bool logKeyCreated = false;
RegistryKey logKey = null;
try {
logKey = eventLogKey.OpenSubKey (sourceData.LogName, true);
if (logKey == null) {
ValidateCustomerLogName (sourceData.LogName,
sourceData.MachineName);
logKey = eventLogKey.CreateSubKey (sourceData.LogName);
logKey.SetValue ("Sources", new string [] { sourceData.LogName,
sourceData.Source });
UpdateLogRegistry (logKey);
using (RegistryKey sourceKey = logKey.CreateSubKey (sourceData.LogName)) {
UpdateSourceRegistry (sourceKey, sourceData);
}
logKeyCreated = true;
}
if (sourceData.LogName != sourceData.Source) {
if (!logKeyCreated) {
string [] sources = (string []) logKey.GetValue ("Sources");
if (sources == null) {
logKey.SetValue ("Sources", new string [] { sourceData.LogName,
sourceData.Source });
} else {
bool found = false;
for (int i = 0; i < sources.Length; i++) {
if (sources [i] == sourceData.Source) {
found = true;
break;
}
}
if (!found) {
string [] newSources = new string [sources.Length + 1];
Array.Copy (sources, 0, newSources, 0, sources.Length);
newSources [sources.Length] = sourceData.Source;
logKey.SetValue ("Sources", newSources);
}
}
}
using (RegistryKey sourceKey = logKey.CreateSubKey (sourceData.Source)) {
UpdateSourceRegistry (sourceKey, sourceData);
}
}
} finally {
if (logKey != null)
logKey.Close ();
}
}
}
示例7: Application_Error
protected void Application_Error(object sender, EventArgs e)
{
var objErr = Server.GetLastError().GetBaseException();
var source = new EventSourceCreationData("ECO.Web", "Application");
if (!EventLog.SourceExists(source.Source, source.MachineName))
EventLog.CreateEventSource(source);
EventLog.WriteEntry(source.Source, GetInnerMostException(objErr).Message);
}
示例8: Install
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
if (!EventLog.SourceExists(eventSourceName, "."))
{
EventSourceCreationData eventLogData = new EventSourceCreationData(eventSourceName, "Application");
eventLogData.MachineName = ".";
EventLog.CreateEventSource(eventLogData);
}
}
示例9: EventLogSink
/// <summary>
/// Construct a sink posting to the Windows event log, creating the specified <paramref name="source"/> if it does not exist.
/// </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. Possible values include Application, System, or a custom event log.</param>
/// <param name="textFormatter">Supplies culture-specific formatting information, or null.</param>
/// <param name="machineName">The name of the machine hosting the event log written to.</param>
public EventLogSink(string source, string logName, ITextFormatter textFormatter, string machineName)
{
if (source == null) throw new ArgumentNullException("source");
_textFormatter = textFormatter;
_source = source;
var sourceData = new EventSourceCreationData(source, logName) { MachineName = machineName };
if (!System.Diagnostics.EventLog.SourceExists(source, machineName)) System.Diagnostics.EventLog.CreateEventSource(sourceData);
}
示例10: DiagnosticsLogger
/// <summary>
/// Creates a logger based on <see cref = "EventLog" />.
/// </summary>
/// <param name = "logName"><see cref = "EventLog.Log" /></param>
/// <param name = "machineName"><see cref = "EventLog.MachineName" /></param>
/// <param name = "source"><see cref = "EventLog.Source" /></param>
public DiagnosticsLogger(string logName, string machineName, string source)
{
// Create the source, if it does not already exist.
if (!EventLog.SourceExists(source, machineName))
{
var eventSourceCreationData = new EventSourceCreationData(source, logName);
eventSourceCreationData.MachineName = machineName;
EventLog.CreateEventSource(eventSourceCreationData);
}
eventLog = new EventLog(logName, machineName, source);
}
示例11: InsertarWarningEventLog
public static void InsertarWarningEventLog(string strOrigen, System.Exception e)
{
// Verifico que en el EventLog exista el origen
if (!EventLog.SourceExists(strOrigen, "."))
{
// Si el origen no existe en el EventLog, lo creo dentro del grupo de errores de Aplicacion
EventSourceCreationData srcData = new EventSourceCreationData(strOrigen, "Application");
EventLog.CreateEventSource(srcData);
}
// Escribo el registro del warning en el EventLog
EventLog.WriteEntry(strOrigen, e.Source + "\n" + e.Message + "\n" + e.StackTrace, EventLogEntryType.Warning);
}
示例12: InsertarInformacionEventLog
public static void InsertarInformacionEventLog(string strOrigen, string strMensaje)
{
// Verifico que en el EventLog exista el orig
if (!EventLog.SourceExists(strOrigen, "."))
{
// Si el origen no existe en el EventLog, lo creo dentro del grupo de errores de Aplicacion
EventSourceCreationData srcData = new EventSourceCreationData(strOrigen, "Application");
EventLog.CreateEventSource(srcData);
}
// Escribo el registro del warning en el EventLog
EventLog.WriteEntry(strOrigen, strMensaje, EventLogEntryType.Information, 123);
}
示例13: LogToEvent
//// GET: api/Heroku
//public string Get()
//{
// LogToEvent("Entered Get", EventLogEntryType.Information);
// return "Get Successful";
//}
private void LogToEvent(string msg, EventLogEntryType errorType)
{
// create event source
string strSource = "Wlocate";
string instanceName = System.AppDomain.CurrentDomain.BaseDirectory;
EventSourceCreationData evtSource = new EventSourceCreationData(strSource, strSource);
if (!EventLog.SourceExists(strSource))
EventLog.CreateEventSource(evtSource);
// check error type
string strLog = String.Format("{0}: {1}\r\n\"{2}\"", instanceName, strSource, msg);
EventLog.WriteEntry(strSource, strLog, errorType);
}
示例14: EventLogger
/// <summary>
/// Initializes the logger by creating the necessary
/// <see cref="EventLog"/> source.
/// </summary>
public EventLogger()
{
string source = ConfigurationSettings.Settings.ConnectionString;
// Create the source, if it does not already exist.
if (!EventLog.SourceExists(source, MACHINE_NAME))
{
EventSourceCreationData sourceData = new EventSourceCreationData(source, LOG_NAME);
EventLog.CreateEventSource(sourceData);
}
_eventLog = new EventLog(LOG_NAME, MACHINE_NAME, source);
}
示例15: WriteToEventLog
public static void WriteToEventLog(string msg, string source) {
if (!EventLog.SourceExists(source)) {
EventSourceCreationData sourceData = new EventSourceCreationData(source, source);
EventLog.CreateEventSource(sourceData);
}
EventLog log = new EventLog();
log.Source = source;
log.WriteEntry(msg);
}