You've already forked linux-packaging-mono
Imported Upstream version 5.10.0.69
Former-commit-id: fc39669a0b707dd3c063977486506b6793da2890
This commit is contained in:
parent
d8f8abd549
commit
e2950ec768
11
external/corefx/src/System.Diagnostics.EventLog/pkg/System.Diagnostics.EventLog.pkgproj
vendored
Normal file
11
external/corefx/src/System.Diagnostics.EventLog/pkg/System.Diagnostics.EventLog.pkgproj
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ref\System.Diagnostics.EventLog.csproj">
|
||||
<SupportedFramework>net461;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\src\System.Diagnostics.EventLog.csproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
@@ -20,7 +20,6 @@ namespace System.Diagnostics
|
||||
public long InstanceId { get { throw null; } set { } }
|
||||
}
|
||||
[System.ComponentModel.DefaultEventAttribute("EntryWritten")]
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("Provides interaction with Windows event logs.")]
|
||||
public partial class EventLog : System.ComponentModel.Component, System.ComponentModel.ISupportInitialize
|
||||
{
|
||||
public EventLog() { }
|
||||
@@ -29,44 +28,34 @@ namespace System.Diagnostics
|
||||
public EventLog(string logName, string machineName, string source) { }
|
||||
[System.ComponentModel.BrowsableAttribute(false)]
|
||||
[System.ComponentModel.DefaultValueAttribute(false)]
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("Indicates if the component monitors the event log for changes.")]
|
||||
public bool EnableRaisingEvents { get { throw null; } set { } }
|
||||
[System.ComponentModel.BrowsableAttribute(false)]
|
||||
[System.ComponentModel.DesignerSerializationVisibilityAttribute((System.ComponentModel.DesignerSerializationVisibility)(0))]
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The contents of the log.")]
|
||||
public System.Diagnostics.EventLogEntryCollection Entries { get { throw null; } }
|
||||
[System.ComponentModel.DefaultValueAttribute("")]
|
||||
[System.ComponentModel.ReadOnlyAttribute(true)]
|
||||
[System.ComponentModel.SettingsBindableAttribute(true)]
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("Gets or sets the name of the log to read from and write to.")]
|
||||
public string Log { get { throw null; } set { } }
|
||||
[System.ComponentModel.BrowsableAttribute(false)]
|
||||
public string LogDisplayName { get { throw null; } }
|
||||
[System.ComponentModel.DefaultValueAttribute(".")]
|
||||
[System.ComponentModel.ReadOnlyAttribute(true)]
|
||||
[System.ComponentModel.SettingsBindableAttribute(true)]
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The machine on which this event log resides.")]
|
||||
public string MachineName { get { throw null; } set { } }
|
||||
[System.ComponentModel.BrowsableAttribute(false)]
|
||||
[System.ComponentModel.DesignerSerializationVisibilityAttribute((System.ComponentModel.DesignerSerializationVisibility)(0))]
|
||||
[System.Runtime.InteropServices.ComVisibleAttribute(false)]
|
||||
public long MaximumKilobytes { get { throw null; } set { } }
|
||||
[System.ComponentModel.BrowsableAttribute(false)]
|
||||
[System.Runtime.InteropServices.ComVisibleAttribute(false)]
|
||||
public int MinimumRetentionDays { get { throw null; } }
|
||||
[System.ComponentModel.BrowsableAttribute(false)]
|
||||
[System.Runtime.InteropServices.ComVisibleAttribute(false)]
|
||||
public System.Diagnostics.OverflowAction OverflowAction { get { throw null; } }
|
||||
[System.ComponentModel.DefaultValueAttribute("")]
|
||||
[System.ComponentModel.ReadOnlyAttribute(true)]
|
||||
[System.ComponentModel.SettingsBindableAttribute(true)]
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The application name (source name) to use when writing to the event log.")]
|
||||
public string Source { get { throw null; } set { } }
|
||||
[System.ComponentModel.BrowsableAttribute(false)]
|
||||
[System.ComponentModel.DefaultValueAttribute(null)]
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The object used to marshal the event handler calls issued as a result of an EventLog change.")]
|
||||
public System.ComponentModel.ISynchronizeInvoke SynchronizingObject { [System.Security.Permissions.HostProtectionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Synchronization=true)]get { throw null; } set { } }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("Raised each time any application writes an entry to the event log.")]
|
||||
public System.ComponentModel.ISynchronizeInvoke SynchronizingObject { [System.Security.Permissions.HostProtectionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Synchronization = true)]get { throw null; } set { } }
|
||||
public event System.Diagnostics.EntryWrittenEventHandler EntryWritten { add { } remove { } }
|
||||
public void BeginInit() { }
|
||||
public void Clear() { }
|
||||
@@ -86,9 +75,7 @@ namespace System.Diagnostics
|
||||
public static System.Diagnostics.EventLog[] GetEventLogs() { throw null; }
|
||||
public static System.Diagnostics.EventLog[] GetEventLogs(string machineName) { throw null; }
|
||||
public static string LogNameFromSourceName(string source, string machineName) { throw null; }
|
||||
[System.Runtime.InteropServices.ComVisibleAttribute(false)]
|
||||
public void ModifyOverflowPolicy(System.Diagnostics.OverflowAction action, int retentionDays) { }
|
||||
[System.Runtime.InteropServices.ComVisibleAttribute(false)]
|
||||
public void RegisterDisplayName(string resourceFile, long resourceId) { }
|
||||
public static bool SourceExists(string source) { throw null; }
|
||||
public static bool SourceExists(string source, string machineName) { throw null; }
|
||||
@@ -102,9 +89,7 @@ namespace System.Diagnostics
|
||||
public static void WriteEntry(string source, string message, System.Diagnostics.EventLogEntryType type, int eventID) { }
|
||||
public static void WriteEntry(string source, string message, System.Diagnostics.EventLogEntryType type, int eventID, short category) { }
|
||||
public static void WriteEntry(string source, string message, System.Diagnostics.EventLogEntryType type, int eventID, short category, byte[] rawData) { }
|
||||
[System.Runtime.InteropServices.ComVisibleAttribute(false)]
|
||||
public void WriteEvent(System.Diagnostics.EventInstance instance, byte[] data, params object[] values) { }
|
||||
[System.Runtime.InteropServices.ComVisibleAttribute(false)]
|
||||
public void WriteEvent(System.Diagnostics.EventInstance instance, params object[] values) { }
|
||||
public static void WriteEvent(string source, System.Diagnostics.EventInstance instance, byte[] data, params object[] values) { }
|
||||
public static void WriteEvent(string source, System.Diagnostics.EventInstance instance, params object[] values) { }
|
||||
@@ -114,35 +99,20 @@ namespace System.Diagnostics
|
||||
public sealed partial class EventLogEntry : System.ComponentModel.Component, System.Runtime.Serialization.ISerializable
|
||||
{
|
||||
internal EventLogEntry() { }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The category for this message.")]
|
||||
public string Category { get { throw null; } }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("An application-specific category number assigned to this entry.")]
|
||||
public short CategoryNumber { get { throw null; } }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The binary data associated with this entry in the event log.")]
|
||||
public byte[] Data { get { throw null; } }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The type of entry - Information, Warning, etc.")]
|
||||
public System.Diagnostics.EventLogEntryType EntryType { get { throw null; } }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The number identifying the message for this source.")]
|
||||
[System.ObsoleteAttribute("This property has been deprecated. Please use System.Diagnostics.EventLogEntry.InstanceId instead. http://go.microsoft.com/fwlink/?linkid=14202")]
|
||||
public int EventID { get { throw null; } }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The sequence of this entry in the event log.")]
|
||||
public int Index { get { throw null; } }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The full number identifying the message in the event message dll.")]
|
||||
[System.Runtime.InteropServices.ComVisibleAttribute(false)]
|
||||
public long InstanceId { get { throw null; } }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The machine on which this event log resides.")]
|
||||
public string MachineName { get { throw null; } }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The text of the message for this entry.")]
|
||||
public string Message { get { throw null; } }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The application-supplied strings used in the message.")]
|
||||
public string[] ReplacementStrings { get { throw null; } }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The name of the application that wrote this entry.")]
|
||||
public string Source { get { throw null; } }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The time at which the application logged this entry.")]
|
||||
public System.DateTime TimeGenerated { get { throw null; } }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The time at which the system logged this entry to the event log.")]
|
||||
public System.DateTime TimeWritten { get { throw null; } }
|
||||
[System.Diagnostics.MonitoringDescriptionAttribute("The username of the account associated with this entry by the writing application.")]
|
||||
public string UserName { get { throw null; } }
|
||||
public bool Equals(System.Diagnostics.EventLogEntry otherEntry) { throw null; }
|
||||
void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
|
||||
|
@@ -1,10 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
netcoreapp-Windows_NT;
|
||||
<PackageConfigurations>
|
||||
netcoreapp2.0-Windows_NT;
|
||||
netfx;
|
||||
netstandard;
|
||||
</PackageConfigurations>
|
||||
<BuildConfigurations>
|
||||
$(PackageConfigurations)
|
||||
netcoreapp-Windows_NT;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
@@ -0,0 +1,7 @@
|
||||
advapi32.dll!ClearEventLog
|
||||
advapi32.dll!CloseEventLog
|
||||
advapi32.dll!GetNumberOfEventLogRecords
|
||||
advapi32.dll!GetOldestEventLogRecord
|
||||
advapi32.dll!NotifyChangeEventLog
|
||||
advapi32.dll!OpenEventLog
|
||||
advapi32.dll!ReadEventLog
|
@@ -117,72 +117,6 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="EventLogDesc" xml:space="preserve">
|
||||
<value>Provides interaction with Windows event logs.</value>
|
||||
</data>
|
||||
<data name="LogEntries" xml:space="preserve">
|
||||
<value>The contents of the log.</value>
|
||||
</data>
|
||||
<data name="LogEntryCategory" xml:space="preserve">
|
||||
<value>The category for this message.</value>
|
||||
</data>
|
||||
<data name="LogEntryCategoryNumber" xml:space="preserve">
|
||||
<value>An application-specific category number assigned to this entry.</value>
|
||||
</data>
|
||||
<data name="LogEntryData" xml:space="preserve">
|
||||
<value>The binary data associated with this entry in the event log.</value>
|
||||
</data>
|
||||
<data name="LogEntryEntryType" xml:space="preserve">
|
||||
<value>The type of entry - Information, Warning, etc.</value>
|
||||
</data>
|
||||
<data name="LogEntryEventID" xml:space="preserve">
|
||||
<value>The number identifying the message for this source.</value>
|
||||
</data>
|
||||
<data name="LogEntryIndex" xml:space="preserve">
|
||||
<value>The sequence of this entry in the event log.</value>
|
||||
</data>
|
||||
<data name="LogEntryMachineName" xml:space="preserve">
|
||||
<value>The machine on which this event log resides.</value>
|
||||
</data>
|
||||
<data name="LogEntryMessage" xml:space="preserve">
|
||||
<value>The text of the message for this entry.</value>
|
||||
</data>
|
||||
<data name="LogEntryReplacementStrings" xml:space="preserve">
|
||||
<value>The application-supplied strings used in the message.</value>
|
||||
</data>
|
||||
<data name="LogEntryResourceId" xml:space="preserve">
|
||||
<value>The full number identifying the message in the event message dll.</value>
|
||||
</data>
|
||||
<data name="LogEntrySource" xml:space="preserve">
|
||||
<value>The name of the application that wrote this entry.</value>
|
||||
</data>
|
||||
<data name="LogEntryTimeGenerated" xml:space="preserve">
|
||||
<value>The time at which the application logged this entry.</value>
|
||||
</data>
|
||||
<data name="LogEntryTimeWritten" xml:space="preserve">
|
||||
<value>The time at which the system logged this entry to the event log.</value>
|
||||
</data>
|
||||
<data name="LogEntryUserName" xml:space="preserve">
|
||||
<value>The username of the account associated with this entry by the writing application.</value>
|
||||
</data>
|
||||
<data name="LogEntryWritten" xml:space="preserve">
|
||||
<value>Raised each time any application writes an entry to the event log.</value>
|
||||
</data>
|
||||
<data name="LogLog" xml:space="preserve">
|
||||
<value>Gets or sets the name of the log to read from and write to.</value>
|
||||
</data>
|
||||
<data name="LogMonitoring" xml:space="preserve">
|
||||
<value>Indicates if the component monitors the event log for changes.</value>
|
||||
</data>
|
||||
<data name="LogSource" xml:space="preserve">
|
||||
<value>The application name (source name) to use when writing to the event log.</value>
|
||||
</data>
|
||||
<data name="LogSynchronizingObject" xml:space="preserve">
|
||||
<value>The object used to marshal the event handler calls issued as a result of an EventLog change.</value>
|
||||
</data>
|
||||
<data name="LogMachineName" xml:space="preserve">
|
||||
<value>The name of the machine on which to read or write events.</value>
|
||||
</data>
|
||||
<data name="BadLogName" xml:space="preserve">
|
||||
<value>Event log names must consist of printable characters and cannot contain \\, *, ?, or spaces</value>
|
||||
</data>
|
||||
@@ -232,7 +166,7 @@
|
||||
<value>Cannot open registry key {0}\\{1}\\{2}.</value>
|
||||
</data>
|
||||
<data name="LocalSourceAlreadyExists" xml:space="preserve">
|
||||
<value>Source {0} already exists on the computer '{1}'.</value>
|
||||
<value>Source {0} already exists on the local computer.</value>
|
||||
</data>
|
||||
<data name="LocalSourceNotRegistered" xml:space="preserve">
|
||||
<value>Source {0} is not registered on the local computer.</value>
|
||||
|
@@ -11,11 +11,13 @@
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp2.0-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp2.0-Windows_NT-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
|
||||
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
|
||||
<ItemGroup Condition="$(TargetGroup.StartsWith('netcoreapp'))">
|
||||
<Compile Include="System\Diagnostics\CompModSwitches.cs" />
|
||||
<Compile Include="System\Diagnostics\EntryWrittenEventArgs.cs" />
|
||||
<Compile Include="System\Diagnostics\EntryWrittenEventHandler.cs" />
|
||||
|
@@ -8,22 +8,8 @@ namespace System.ComponentModel
|
||||
{
|
||||
internal static class CompModSwitches
|
||||
{
|
||||
private static volatile BooleanSwitch s_commonDesignerServices;
|
||||
private static volatile TraceSwitch s_eventLog;
|
||||
|
||||
public static BooleanSwitch CommonDesignerServices
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_commonDesignerServices == null)
|
||||
{
|
||||
s_commonDesignerServices = new BooleanSwitch(nameof(CommonDesignerServices), "Assert if any common designer service is not found.");
|
||||
}
|
||||
|
||||
return s_commonDesignerServices;
|
||||
}
|
||||
}
|
||||
|
||||
public static TraceSwitch EventLog
|
||||
{
|
||||
get
|
||||
@@ -32,9 +18,9 @@ namespace System.ComponentModel
|
||||
{
|
||||
s_eventLog = new TraceSwitch(nameof(EventLog), "Enable tracing for the EventLog component.");
|
||||
}
|
||||
|
||||
|
||||
return s_eventLog;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,14 +2,12 @@
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Microsoft.Win32;
|
||||
@@ -17,7 +15,10 @@ using Microsoft.Win32.SafeHandles;
|
||||
|
||||
namespace System.Diagnostics
|
||||
{
|
||||
[DefaultEvent("EntryWritten"), MonitoringDescription("Provides interaction with Windows event logs.")]
|
||||
/// <summary>
|
||||
/// Provides interaction with Windows event logs.
|
||||
/// </summary>
|
||||
[DefaultEvent("EntryWritten")]
|
||||
public class EventLog : Component, ISupportInitialize
|
||||
{
|
||||
private const string EventLogKey = "SYSTEM\\CurrentControlSet\\Services\\EventLog";
|
||||
@@ -26,7 +27,7 @@ namespace System.Diagnostics
|
||||
private const int DefaultMaxSize = 512 * 1024;
|
||||
private const int DefaultRetention = 7 * SecondsPerDay;
|
||||
private const int SecondsPerDay = 60 * 60 * 24;
|
||||
|
||||
|
||||
private EventLogInternal _underlyingEventLog;
|
||||
|
||||
public EventLog() : this(string.Empty, ".", string.Empty)
|
||||
@@ -46,9 +47,11 @@ namespace System.Diagnostics
|
||||
_underlyingEventLog = new EventLogInternal(logName, machineName, source, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The contents of the log.
|
||||
/// </summary>
|
||||
[Browsable(false)]
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
[MonitoringDescription("The contents of the log.")]
|
||||
public EventLogEntryCollection Entries
|
||||
{
|
||||
get
|
||||
@@ -66,8 +69,10 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the log to read from and write to.
|
||||
/// </summary>
|
||||
[ReadOnly(true)]
|
||||
[MonitoringDescription("Gets or sets the name of the log to read from and write to.")]
|
||||
[DefaultValue("")]
|
||||
[SettingsBindable(true)]
|
||||
public string Log
|
||||
@@ -92,8 +97,10 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The machine on which this event log resides.
|
||||
/// </summary>
|
||||
[ReadOnly(true)]
|
||||
[MonitoringDescription("The machine on which this event log resides.")]
|
||||
[DefaultValue(".")]
|
||||
[SettingsBindable(true)]
|
||||
public string MachineName
|
||||
@@ -120,22 +127,19 @@ namespace System.Diagnostics
|
||||
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
[Browsable(false)]
|
||||
[ComVisible(false)]
|
||||
public long MaximumKilobytes
|
||||
public long MaximumKilobytes
|
||||
{
|
||||
get => _underlyingEventLog.MaximumKilobytes;
|
||||
set => _underlyingEventLog.MaximumKilobytes = value;
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
[ComVisible(false)]
|
||||
public OverflowAction OverflowAction
|
||||
{
|
||||
get => _underlyingEventLog.OverflowAction;
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
[ComVisible(false)]
|
||||
public int MinimumRetentionDays
|
||||
{
|
||||
get => _underlyingEventLog.MinimumRetentionDays;
|
||||
@@ -151,8 +155,10 @@ namespace System.Diagnostics
|
||||
return GetService(service);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the component monitors the event log for changes.
|
||||
/// </summary>
|
||||
[Browsable(false)]
|
||||
[MonitoringDescription("Indicates if the component monitors the event log for changes.")]
|
||||
[DefaultValue(false)]
|
||||
public bool EnableRaisingEvents
|
||||
{
|
||||
@@ -160,17 +166,21 @@ namespace System.Diagnostics
|
||||
set => _underlyingEventLog.EnableRaisingEvents = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The object used to marshal the event handler calls issued as a result of an EventLog change.
|
||||
/// </summary>
|
||||
[Browsable(false)]
|
||||
[DefaultValue(null)]
|
||||
[MonitoringDescription("The object used to marshal the event handler calls issued as a result of an EventLog change.")]
|
||||
public ISynchronizeInvoke SynchronizingObject
|
||||
{
|
||||
get => _underlyingEventLog.SynchronizingObject;
|
||||
set => _underlyingEventLog.SynchronizingObject = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The application name (source name) to use when writing to the event log.
|
||||
/// </summary>
|
||||
[ReadOnly(true)]
|
||||
[MonitoringDescription("The application name (source name) to use when writing to the event log.")]
|
||||
[DefaultValue("")]
|
||||
[SettingsBindable(true)]
|
||||
public string Source
|
||||
@@ -192,7 +202,9 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[MonitoringDescription("Raised each time any application writes an entry to the event log.")]
|
||||
/// <summary>
|
||||
/// Raised each time any application writes an entry to the event log.
|
||||
/// </summary>
|
||||
public event EntryWrittenEventHandler EntryWritten
|
||||
{
|
||||
add
|
||||
@@ -478,7 +490,7 @@ namespace System.Diagnostics
|
||||
}
|
||||
finally
|
||||
{
|
||||
mutex?.ReleaseMutex();
|
||||
mutex?.ReleaseMutex();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -747,13 +759,11 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public void ModifyOverflowPolicy(OverflowAction action, int retentionDays)
|
||||
{
|
||||
_underlyingEventLog.ModifyOverflowPolicy(action, retentionDays);
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public void RegisterDisplayName(string resourceFile, long resourceId)
|
||||
{
|
||||
_underlyingEventLog.RegisterDisplayName(resourceFile, resourceId);
|
||||
@@ -1005,13 +1015,11 @@ namespace System.Diagnostics
|
||||
_underlyingEventLog.WriteEntry(message, type, eventID, category, rawData);
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public void WriteEvent(EventInstance instance, params Object[] values)
|
||||
{
|
||||
WriteEvent(instance, null, values);
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public void WriteEvent(EventInstance instance, byte[] data, params Object[] values)
|
||||
{
|
||||
_underlyingEventLog.WriteEvent(instance, data, values);
|
||||
@@ -1046,4 +1054,4 @@ namespace System.Diagnostics
|
||||
return source;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -37,7 +37,9 @@ namespace System.Diagnostics
|
||||
throw new PlatformNotSupportedException();
|
||||
}
|
||||
|
||||
[MonitoringDescription("The machine on which this event log resides.")]
|
||||
/// <summary>
|
||||
/// The machine on which this event log resides.
|
||||
/// </summary>
|
||||
public string MachineName
|
||||
{
|
||||
get
|
||||
@@ -60,7 +62,9 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[MonitoringDescription("The binary data associated with this entry in the event log.")]
|
||||
/// <summary>
|
||||
/// The binary data associated with this entry in the event log.
|
||||
/// </summary>
|
||||
public byte[] Data
|
||||
{
|
||||
get
|
||||
@@ -73,7 +77,9 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[MonitoringDescription("The sequence of this entry in the event log.")]
|
||||
/// <summary>
|
||||
/// The sequence of this entry in the event log.
|
||||
/// </summary>
|
||||
public int Index
|
||||
{
|
||||
get
|
||||
@@ -82,7 +88,9 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[MonitoringDescription("The category for this message.")]
|
||||
/// <summary>
|
||||
/// The category for this message.
|
||||
/// </summary>
|
||||
public string Category
|
||||
{
|
||||
get
|
||||
@@ -101,7 +109,9 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[MonitoringDescription("An application-specific category number assigned to this entry.")]
|
||||
/// <summary>
|
||||
/// An application-specific category number assigned to this entry.
|
||||
/// </summary>
|
||||
public short CategoryNumber
|
||||
{
|
||||
get
|
||||
@@ -110,10 +120,10 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
MonitoringDescription("The number identifying the message for this source."),
|
||||
Obsolete("This property has been deprecated. Please use System.Diagnostics.EventLogEntry.InstanceId instead. http://go.microsoft.com/fwlink/?linkid=14202")
|
||||
]
|
||||
/// <summary>
|
||||
/// The number identifying the message for this source.
|
||||
/// </summary>
|
||||
[Obsolete("This property has been deprecated. Please use System.Diagnostics.EventLogEntry.InstanceId instead. http://go.microsoft.com/fwlink/?linkid=14202")]
|
||||
public int EventID
|
||||
{
|
||||
get
|
||||
@@ -122,7 +132,9 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[MonitoringDescription("The type of entry - Information, Warning, etc.")]
|
||||
/// <summary>
|
||||
/// The type of entry - Information, Warning, etc.
|
||||
/// </summary>
|
||||
public EventLogEntryType EntryType
|
||||
{
|
||||
get
|
||||
@@ -131,7 +143,9 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[MonitoringDescription("The text of the message for this entry.")]
|
||||
/// <summary>
|
||||
/// The text of the message for this entry.
|
||||
/// </summary>
|
||||
public string Message
|
||||
{
|
||||
get
|
||||
@@ -143,7 +157,7 @@ namespace System.Diagnostics
|
||||
string msg = owner.FormatMessageWrapper(dllNames, (uint)msgId, ReplacementStrings);
|
||||
if (msg == null)
|
||||
{
|
||||
StringBuilder msgBuf = new StringBuilder(SR.MessageNotFormatted + msgId + Source);
|
||||
StringBuilder msgBuf = new StringBuilder(SR.Format(SR.MessageNotFormatted, msgId, Source));
|
||||
string[] strings = ReplacementStrings;
|
||||
for (int i = 0; i < strings.Length; i++)
|
||||
{
|
||||
@@ -166,7 +180,9 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[MonitoringDescription("The name of the application that wrote this entry.")]
|
||||
/// <summary>
|
||||
/// The name of the application that wrote this entry.
|
||||
/// </summary>
|
||||
public string Source
|
||||
{
|
||||
get
|
||||
@@ -186,7 +202,9 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[MonitoringDescription("The application-supplied strings used in the message.")]
|
||||
/// <summary>
|
||||
/// The application-supplied strings used in the message.
|
||||
/// </summary>
|
||||
public string[] ReplacementStrings
|
||||
{
|
||||
get
|
||||
@@ -214,10 +232,9 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
MonitoringDescription("The full number identifying the message in the event message dll."),
|
||||
ComVisible(false)
|
||||
]
|
||||
/// <summary>
|
||||
/// The full number identifying the message in the event message dll.
|
||||
/// </summary>
|
||||
public Int64 InstanceId
|
||||
{
|
||||
get
|
||||
@@ -226,7 +243,9 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[MonitoringDescription("The time at which the application logged this entry.")]
|
||||
/// <summary>
|
||||
/// The time at which the application logged this entry.
|
||||
/// </summary>
|
||||
public DateTime TimeGenerated
|
||||
{
|
||||
get
|
||||
@@ -235,7 +254,9 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[MonitoringDescription("The time at which the system logged this entry to the event log.")]
|
||||
/// <summary>
|
||||
/// The time at which the system logged this entry to the event log.
|
||||
/// </summary>
|
||||
public DateTime TimeWritten
|
||||
{
|
||||
get
|
||||
@@ -244,7 +265,9 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[MonitoringDescription("The username of the account associated with this entry by the writing application.")]
|
||||
/// <summary>
|
||||
/// The username of the account associated with this entry by the writing application.
|
||||
/// </summary>
|
||||
public string UserName
|
||||
{
|
||||
get
|
||||
|
@@ -103,4 +103,4 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -105,14 +105,6 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
public EventLogInternal() : this("", ".", "", null)
|
||||
{
|
||||
}
|
||||
|
||||
public EventLogInternal(string logName) : this(logName, ".", "", null)
|
||||
{
|
||||
}
|
||||
|
||||
public EventLogInternal(string logName, string machineName) : this(logName, machineName, "", null)
|
||||
{
|
||||
}
|
||||
@@ -258,7 +250,6 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public long MaximumKilobytes
|
||||
{
|
||||
get
|
||||
@@ -300,7 +291,6 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public OverflowAction OverflowAction
|
||||
{
|
||||
get
|
||||
@@ -324,7 +314,6 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public int MinimumRetentionDays
|
||||
{
|
||||
get
|
||||
@@ -1068,7 +1057,6 @@ namespace System.Diagnostics
|
||||
(0xFF00 & (buf[offset + 1] << 8)) | (0xFF & (buf[offset]));
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public void ModifyOverflowPolicy(OverflowAction action, int retentionDays)
|
||||
{
|
||||
string currentMachineName = this.machineName;
|
||||
@@ -1150,7 +1138,6 @@ namespace System.Diagnostics
|
||||
writeHandle = handle;
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public void RegisterDisplayName(string resourceFile, long resourceId)
|
||||
{
|
||||
string currentMachineName = this.machineName;
|
||||
@@ -1348,26 +1335,6 @@ namespace System.Diagnostics
|
||||
boolFlags[Flag_sourceVerified] = true;
|
||||
}
|
||||
|
||||
public void WriteEntry(string message)
|
||||
{
|
||||
WriteEntry(message, EventLogEntryType.Information, (short)0, 0, null);
|
||||
}
|
||||
|
||||
public void WriteEntry(string message, EventLogEntryType type)
|
||||
{
|
||||
WriteEntry(message, type, (short)0, 0, null);
|
||||
}
|
||||
|
||||
public void WriteEntry(string message, EventLogEntryType type, int eventID)
|
||||
{
|
||||
WriteEntry(message, type, eventID, 0, null);
|
||||
}
|
||||
|
||||
public void WriteEntry(string message, EventLogEntryType type, int eventID, short category)
|
||||
{
|
||||
WriteEntry(message, type, eventID, category, null);
|
||||
}
|
||||
|
||||
public void WriteEntry(string message, EventLogEntryType type, int eventID, short category,
|
||||
byte[] rawData)
|
||||
{
|
||||
@@ -1394,13 +1361,6 @@ namespace System.Diagnostics
|
||||
InternalWriteEvent((uint)eventID, (ushort)category, type, new string[] { message }, rawData, currentMachineName);
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public void WriteEvent(EventInstance instance, params Object[] values)
|
||||
{
|
||||
WriteEvent(instance, null, values);
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public void WriteEvent(EventInstance instance, byte[] data, params Object[] values)
|
||||
{
|
||||
if (instance == null)
|
||||
@@ -1479,7 +1439,7 @@ namespace System.Diagnostics
|
||||
sid, (short)strings.Length, rawData.Length, new HandleRef(this, stringsRootHandle.AddrOfPinnedObject()), rawData);
|
||||
if (!success)
|
||||
{
|
||||
//Trace("WriteEvent", "Throwing Win32Exception");
|
||||
// Trace("WriteEvent", "Throwing Win32Exception");
|
||||
throw SharedUtils.CreateSafeWin32Exception();
|
||||
}
|
||||
}
|
||||
|
@@ -21,18 +21,6 @@ namespace System.Diagnostics
|
||||
MachineName = machineName;
|
||||
}
|
||||
|
||||
private EventSourceCreationData(string source, string logName, string machineName,
|
||||
string messageResourceFile, string parameterResourceFile,
|
||||
string categoryResourceFile, short categoryCount)
|
||||
: this(source, logName, machineName)
|
||||
|
||||
{
|
||||
MessageResourceFile = messageResourceFile;
|
||||
ParameterResourceFile = parameterResourceFile;
|
||||
CategoryResourceFile = categoryResourceFile;
|
||||
CategoryCount = categoryCount;
|
||||
}
|
||||
|
||||
public string LogName { get; set; } = "Application";
|
||||
|
||||
public string MachineName { get; set; } = ".";
|
||||
@@ -57,4 +45,4 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
45
external/corefx/src/System.Diagnostics.EventLog/tests/EventInstanceTests.cs
vendored
Normal file
45
external/corefx/src/System.Diagnostics.EventLog/tests/EventInstanceTests.cs
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.even
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.Diagnostics.Tests
|
||||
{
|
||||
public class EventInstanceTests
|
||||
{
|
||||
// These ids can be any non-negative numbers
|
||||
private const long instanceId = 57;
|
||||
private const int categoryId = 657;
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void EventInstanceCreation()
|
||||
{
|
||||
EventInstance eventInstance = new EventInstance(instanceId, categoryId);
|
||||
|
||||
Assert.Equal(categoryId, eventInstance.CategoryId);
|
||||
Assert.Equal(instanceId, eventInstance.InstanceId);
|
||||
Assert.Equal(EventLogEntryType.Information, eventInstance.EntryType);
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void EventInstanceOutOfRangeException()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new EventInstance(-1, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new EventInstance(0, -1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new EventInstance(-1, -1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new EventInstance(0, int.MaxValue));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new EventInstance(long.MaxValue, 0));
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void EventInstanceCreationWithType()
|
||||
{
|
||||
EventInstance eventInstance = new EventInstance(instanceId, categoryId, EventLogEntryType.Warning);
|
||||
|
||||
Assert.Equal(categoryId, eventInstance.CategoryId);
|
||||
Assert.Equal(instanceId, eventInstance.InstanceId);
|
||||
Assert.Equal(EventLogEntryType.Warning, eventInstance.EntryType);
|
||||
}
|
||||
}
|
||||
}
|
129
external/corefx/src/System.Diagnostics.EventLog/tests/EventLogEntryCollectionTests.cs
vendored
Normal file
129
external/corefx/src/System.Diagnostics.EventLog/tests/EventLogEntryCollectionTests.cs
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.Diagnostics.Tests
|
||||
{
|
||||
public class EventLogEntryCollectionTests
|
||||
{
|
||||
private const string message = "EntryCollectionMessage";
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void CopyingEventLogEntryCollection()
|
||||
{
|
||||
string log = "CopyCollection";
|
||||
string source = "Source_" + nameof(CopyingEventLogEntryCollection);
|
||||
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Source = source;
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEntry(message));
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEntry("Further Testing"));
|
||||
|
||||
EventLogEntryCollection entryCollection = eventLog.Entries;
|
||||
EventLogEntry[] entryCollectionCopied = new EventLogEntry[entryCollection.Count];
|
||||
|
||||
Helpers.RetryOnWin7(() => entryCollection.CopyTo(entryCollectionCopied, 0));
|
||||
int i = 0;
|
||||
foreach (EventLogEntry entry in entryCollection)
|
||||
{
|
||||
Assert.Equal(entry.Message, Helpers.RetryOnWin7(() => entryCollectionCopied[i].Message));
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void CheckingEntryEqualityWithNull()
|
||||
{
|
||||
string log = "NullTest";
|
||||
string source = "Source_" + nameof(CheckingEntryEqualityWithNull);
|
||||
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Source = source;
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEntry(message));
|
||||
Helpers.WaitForEventLog(eventLog, 1);
|
||||
EventLogEntry entry = Helpers.RetryOnWin7(() => eventLog.Entries[eventLog.Entries.Count - 1]);
|
||||
Assert.False(entry.Equals(null));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void CheckingEntryEqualityAndIndex()
|
||||
{
|
||||
string log = "IndexTest";
|
||||
string source = "Source_" + nameof(CheckingEntryEqualityAndIndex);
|
||||
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Source = source;
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEntry(message));
|
||||
Helpers.WaitForEventLog(eventLog, 1); //There is latency between writing and getting the entry
|
||||
EventLogEntry entry = Helpers.RetryOnWin7(() => eventLog.Entries[eventLog.Entries.Count - 1]);
|
||||
Assert.True(entry.Equals(entry));
|
||||
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEntry(message));
|
||||
Helpers.WaitForEventLog(eventLog, 2);
|
||||
EventLogEntry secondEntry = Helpers.RetryOnWin7(() => eventLog.Entries[eventLog.Entries.Count - 1]);
|
||||
Assert.Equal(entry.Index + 1, secondEntry.Index);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void CheckingEntryInEquality()
|
||||
{
|
||||
string log = "InEqualityTest";
|
||||
string source = "Source_" + nameof(CheckingEntryInEquality);
|
||||
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Source = source;
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEntry(message));
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEntry(message));
|
||||
Helpers.WaitForEventLog(eventLog, 2);
|
||||
EventLogEntry entry = Helpers.RetryOnWin7(() => eventLog.Entries[eventLog.Entries.Count - 1]);
|
||||
EventLogEntry secondEntry = Helpers.RetryOnWin7(() => eventLog.Entries[eventLog.Entries.Count - 2]);
|
||||
Assert.False(entry.Equals(secondEntry));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
69
external/corefx/src/System.Diagnostics.EventLog/tests/EventLogTests/EventLogEntryWrittenTest.cs
vendored
Normal file
69
external/corefx/src/System.Diagnostics.EventLog/tests/EventLogTests/EventLogEntryWrittenTest.cs
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Threading;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Diagnostics.Tests
|
||||
{
|
||||
public class EventLogEntryEventWrittenTest
|
||||
{
|
||||
static AutoResetEvent signal;
|
||||
private const string message = "EventLogEntryEventWrittenTestMessage";
|
||||
private int eventCounter;
|
||||
|
||||
public void RaisingEvent(string log, string methodName, bool waitOnEvent = true)
|
||||
{
|
||||
signal = new AutoResetEvent(false);
|
||||
eventCounter = 0;
|
||||
string source = "Source_" + methodName;
|
||||
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Source = source;
|
||||
eventLog.EntryWritten += new EntryWrittenEventHandler((object sourceObject, EntryWrittenEventArgs e) =>
|
||||
{
|
||||
eventCounter += 1;
|
||||
signal.Set();
|
||||
});
|
||||
Helpers.RetryOnWin7(() => eventLog.EnableRaisingEvents = waitOnEvent);
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEntry(message, EventLogEntryType.Information));
|
||||
if (waitOnEvent)
|
||||
{
|
||||
if (!signal.WaitOne(6000))
|
||||
{
|
||||
eventLog.WriteEntry(message, EventLogEntryType.Information);
|
||||
Assert.True(signal.WaitOne(6000));
|
||||
}
|
||||
// The system responds to WriteEntry only if the last write event occurred at least six seconds previously.
|
||||
// This implies that the system will only receive one EntryWritten event notification within a six-second interval, even if more than one event log change occurs.
|
||||
// For more information https://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.entrywritten(v=vs.110).aspx
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void EntryWrittenEventRaised()
|
||||
{
|
||||
RaisingEvent("EnableEvent", nameof(EntryWrittenEventRaised));
|
||||
Assert.NotEqual(0, eventCounter);
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void EntryWrittenEventRaiseDisable()
|
||||
{
|
||||
RaisingEvent("DisableEvent", nameof(EntryWrittenEventRaiseDisable), waitOnEvent: false);
|
||||
Assert.Equal(0, eventCounter);
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,48 +3,163 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
using System;
|
||||
|
||||
namespace System.Diagnostics.Tests
|
||||
{
|
||||
public class EventLogSourceCreationTests
|
||||
{
|
||||
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void CheckSourceExistenceAndDeletion()
|
||||
{
|
||||
if (!AdminHelpers.IsProcessElevated())
|
||||
return;
|
||||
|
||||
string source = Guid.NewGuid().ToString("N");
|
||||
string source = "Source_" + nameof(EventLogSourceCreationTests);
|
||||
string log = "SourceExistenceLog";
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, "MyNewLog");
|
||||
EventLog.CreateEventSource(source, log);
|
||||
Assert.True(EventLog.SourceExists(source));
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
|
||||
Assert.False(EventLog.SourceExists(source));
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void CheckSourceExistsArgumentNull()
|
||||
{
|
||||
if (!AdminHelpers.IsProcessElevated())
|
||||
return;
|
||||
|
||||
Assert.False(EventLog.SourceExists(null));
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void DeleteUnregisteredSource()
|
||||
{
|
||||
if (!AdminHelpers.IsProcessElevated())
|
||||
return;
|
||||
Assert.Throws<ArgumentException>(() => EventLog.DeleteEventSource(Guid.NewGuid().ToString("N")));
|
||||
}
|
||||
|
||||
Assert.Throws<System.ArgumentException>(() => EventLog.DeleteEventSource(Guid.NewGuid().ToString("N")));
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void LogNameNullMeansApplicationLog()
|
||||
{
|
||||
string source = "Source_" + nameof(LogNameNullMeansApplicationLog);
|
||||
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, null);
|
||||
Assert.True(EventLog.SourceExists(source));
|
||||
Assert.Equal("Application", EventLog.LogNameFromSourceName(source, "."));
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void SourceNameNull()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => EventLog.CreateEventSource(null, "logName"));
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void IncorrectLogName()
|
||||
{
|
||||
string source = "Source_" + nameof(IncorrectLogName);
|
||||
Assert.Throws<ArgumentException>(() => EventLog.CreateEventSource(source, "?"));
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void SourceNameMaxLengthExceeded()
|
||||
{
|
||||
string source = new string('s', 254);
|
||||
Assert.Throws<ArgumentException>(() => EventLog.CreateEventSource(source, null));
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void SourceDataNull()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => EventLog.CreateEventSource(null));
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void SourceAlreadyExistsWhenCreatingSource()
|
||||
{
|
||||
string source = "Source_" + nameof(SourceAlreadyExistsWhenCreatingSource);
|
||||
string log = "ExistingSource";
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
Assert.True(EventLog.SourceExists(source));
|
||||
Assert.Throws<ArgumentException>(() => EventLog.CreateEventSource(source, log));
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void LogNameAlreadyExists_Throws()
|
||||
{
|
||||
string source = "Source_" + nameof(LogNameAlreadyExists_Throws);
|
||||
string log = "AppEvent";
|
||||
|
||||
Assert.Throws<ArgumentException>(() => EventLog.CreateEventSource(source, log));
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void EventSourceCategoryCount_Invalid()
|
||||
{
|
||||
string log = "InvalidData";
|
||||
string source = "Source_" + nameof(EventSourceCategoryCount_Invalid);
|
||||
|
||||
EventSourceCreationData mySourceData = new EventSourceCreationData(source, log);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => mySourceData.CategoryCount = -1);
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void MessageResourceFile_Set()
|
||||
{
|
||||
string messageFile = "ResourceFile";
|
||||
string source = "Source" + nameof(MessageResourceFile_Set);
|
||||
string log = "MessageResourceFile";
|
||||
EventSourceCreationData sourceData = new EventSourceCreationData(source, log);
|
||||
sourceData.MessageResourceFile = messageFile;
|
||||
Assert.Equal(messageFile, sourceData.MessageResourceFile);
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void CategoryResourceFile_Set()
|
||||
{
|
||||
string messageFile = "ResourceFile";
|
||||
string source = "Source" + nameof(CategoryResourceFile_Set);
|
||||
string log = "MessageResourceFile";
|
||||
EventSourceCreationData sourceData = new EventSourceCreationData(source, log);
|
||||
sourceData.CategoryResourceFile = messageFile;
|
||||
Assert.Equal(messageFile, sourceData.CategoryResourceFile);
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void ParameterResourceFile_Set()
|
||||
{
|
||||
string messageFile = "ResourceFile";
|
||||
string source = "Source" + nameof(ParameterResourceFile_Set);
|
||||
string log = "MessageResourceFile";
|
||||
EventSourceCreationData sourceData = new EventSourceCreationData(source, log);
|
||||
sourceData.ParameterResourceFile = messageFile;
|
||||
Assert.Equal(messageFile, sourceData.ParameterResourceFile);
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void CategoryCount_Set()
|
||||
{
|
||||
string source = "Source" + nameof(CategoryCount_Set);
|
||||
string log = "MessageResourceFile";
|
||||
EventSourceCreationData sourceData = new EventSourceCreationData(source, log);
|
||||
sourceData.CategoryCount = 2;
|
||||
Assert.Equal(2, sourceData.CategoryCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,75 +2,349 @@
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Diagnostics.Tests
|
||||
{
|
||||
public class EventLogTests
|
||||
public class EventLogTests : FileCleanupTestBase
|
||||
{
|
||||
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void EventLogReinitializationException()
|
||||
{
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.BeginInit();
|
||||
Assert.Throws<InvalidOperationException>(() => eventLog.BeginInit());
|
||||
eventLog.EndInit();
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
|
||||
public void ClearLogTest()
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void ClearLog()
|
||||
{
|
||||
if (!AdminHelpers.IsProcessElevated())
|
||||
return;
|
||||
string log = "ClearTest";
|
||||
string source = "Source_" + nameof(ClearLog);
|
||||
|
||||
string source = Guid.NewGuid().ToString("N");
|
||||
string logName = Guid.NewGuid().ToString("N");
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, logName);
|
||||
using (EventLog myLog = new EventLog())
|
||||
EventLog.CreateEventSource(source, log);
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
myLog.Source = source;
|
||||
myLog.WriteEntry("Writing to event log.");
|
||||
Assert.True(myLog.Entries.Count != 0);
|
||||
myLog.Clear();
|
||||
Assert.Equal(0, myLog.Entries.Count);
|
||||
eventLog.Source = source;
|
||||
eventLog.Clear();
|
||||
Assert.Equal(0, Helpers.RetryOnWin7((() => eventLog.Entries.Count)));
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEntry("Writing to event log."));
|
||||
Helpers.WaitForEventLog(eventLog, 1);
|
||||
Assert.Equal(1, Helpers.RetryOnWin7((() => eventLog.Entries.Count)));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void ApplicationEventLog_Count()
|
||||
{
|
||||
using ( EventLog ael = new EventLog("Application"))
|
||||
{
|
||||
Assert.InRange(ael.Entries.Count, 1, Int32.MaxValue);
|
||||
using (EventLog eventLog = new EventLog("Application"))
|
||||
{
|
||||
Assert.InRange(Helpers.RetryOnWin7((() => eventLog.Entries.Count)), 1, Int32.MaxValue);
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
|
||||
public void DeleteLogTest()
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void DeleteLog()
|
||||
{
|
||||
if (!AdminHelpers.IsProcessElevated())
|
||||
return;
|
||||
string log = "DeleteTest";
|
||||
string source = "Source_" + nameof(DeleteLog);
|
||||
|
||||
string source = Guid.NewGuid().ToString("N");
|
||||
string logName = Guid.NewGuid().ToString("N");
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, logName);
|
||||
Assert.True(EventLog.Exists(logName));
|
||||
EventLog.CreateEventSource(source, log);
|
||||
Assert.True(EventLog.Exists(log));
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.Delete(logName);
|
||||
Assert.False(EventLog.Exists(logName));
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
Assert.False(EventLog.Exists(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void CheckLogName_Get()
|
||||
{
|
||||
using (EventLog eventLog = new EventLog("Application"))
|
||||
{
|
||||
Assert.Equal("Application", eventLog.LogDisplayName);
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void CheckMachineName_Get()
|
||||
{
|
||||
using (EventLog eventLog = new EventLog("Application"))
|
||||
{
|
||||
Assert.Equal(".", eventLog.MachineName);
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void GetLogDisplayName_NotSet_Throws()
|
||||
{
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Log = Guid.NewGuid().ToString("N");
|
||||
Assert.Throws<InvalidOperationException>(() => eventLog.LogDisplayName);
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void GetLogDisplayName_Set()
|
||||
{
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Log = "Application";
|
||||
Assert.Equal("Application", eventLog.LogDisplayName);
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void EventLogs_Get()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => EventLog.GetEventLogs(""));
|
||||
EventLog[] eventLogCollection = EventLog.GetEventLogs();
|
||||
Assert.Contains(eventLogCollection, eventlog => eventlog.Log.Equals("Application"));
|
||||
Assert.Contains(eventLogCollection, eventlog => eventlog.Log.Equals("Security"));
|
||||
Assert.Contains(eventLogCollection, eventlog => eventlog.Log.Equals("System"));
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void GetMaxKilobytes_Set()
|
||||
{
|
||||
string source = "Source_" + nameof(GetMaxKilobytes_Set);
|
||||
string log = "maxKilobytesLog";
|
||||
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Source = source;
|
||||
eventLog.MaximumKilobytes = 0x400;
|
||||
Assert.Equal(0x400, eventLog.MaximumKilobytes);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void MaxKilobytesOutOfRangeException()
|
||||
{
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Log = "Application";
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => eventLog.MaximumKilobytes = 2);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => eventLog.MaximumKilobytes = 0x3FFFC1);
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void OverflowAndRetention_Set()
|
||||
{
|
||||
string source = "Source_" + nameof(OverflowAndRetention_Set);
|
||||
string log = "Overflow_Set";
|
||||
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Source = source;
|
||||
|
||||
// The second argument is only used when the overflow policy is set to OverWrite Older
|
||||
eventLog.ModifyOverflowPolicy(OverflowAction.DoNotOverwrite, 1);
|
||||
Assert.Equal(OverflowAction.DoNotOverwrite, eventLog.OverflowAction);
|
||||
|
||||
// -1 means overflow action is donot OverWrite
|
||||
Assert.Equal(-1, eventLog.MinimumRetentionDays);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void Overflow_OverWriteOlderAndRetention_Set()
|
||||
{
|
||||
string source = "Source_" + nameof(OverflowAndRetention_Set);
|
||||
string log = "Overflow_Set";
|
||||
int retentionDays = 30; // A number between 0 and 365 should work
|
||||
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Source = source;
|
||||
|
||||
// The second argument is only used when the overflow policy is set to OverWrite Older
|
||||
eventLog.ModifyOverflowPolicy(OverflowAction.OverwriteOlder, retentionDays);
|
||||
Assert.Equal(OverflowAction.OverwriteOlder, eventLog.OverflowAction);
|
||||
Assert.Equal(retentionDays, eventLog.MinimumRetentionDays);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void OverflowAndRetentionDaysOutOfRange()
|
||||
{
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Log = "Application";
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => eventLog.ModifyOverflowPolicy(OverflowAction.OverwriteOlder, 400));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void MachineName_Set()
|
||||
{
|
||||
string source = "Source_" + nameof(MachineName_Set);
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Log = "Application";
|
||||
eventLog.MachineName = Environment.MachineName.ToLowerInvariant();
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, eventLog.LogDisplayName);
|
||||
Assert.Equal(eventLog.MachineName, Environment.MachineName.ToLowerInvariant());
|
||||
Assert.True(EventLog.SourceExists(source, Environment.MachineName.ToLowerInvariant()));
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void RegisterDisplayLogName()
|
||||
{
|
||||
string log = "DisplayName";
|
||||
string source = "Source_" + nameof(RegisterDisplayLogName);
|
||||
string messageFile = GetTestFilePath();
|
||||
long DisplayNameMsgId = 42; // It could be any number
|
||||
EventSourceCreationData sourceData = new EventSourceCreationData(source, log);
|
||||
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(sourceData);
|
||||
log = EventLog.LogNameFromSourceName(source, ".");
|
||||
using (EventLog eventLog = new EventLog(log, ".", source))
|
||||
{
|
||||
if (messageFile.Length > 0)
|
||||
{
|
||||
eventLog.RegisterDisplayName(messageFile, DisplayNameMsgId);
|
||||
}
|
||||
Assert.Equal(log, eventLog.LogDisplayName);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void InvalidFormatOrNullLogName()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new EventLog(null));
|
||||
Assert.Throws<ArgumentException>(() => new EventLog("?"));
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]
|
||||
public void EventLog_EnableRaisingEvents_DefaultFalse()
|
||||
{
|
||||
using (EventLog eventLog = new EventLog("log"))
|
||||
{
|
||||
Assert.False(eventLog.EnableRaisingEvents);
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void InvalidFormatOrNullDeleteLogName()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => EventLog.Delete(null));
|
||||
Assert.Throws<InvalidOperationException>(() => EventLog.Delete("?"));
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void InvalidLogExistsLogName()
|
||||
{
|
||||
Assert.False(EventLog.Exists(null));
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void InvalidMachineName()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => EventLog.Exists("Application", ""));
|
||||
Assert.Throws<ArgumentException>(() => EventLog.Delete("", ""));
|
||||
Assert.Throws<ArgumentException>(() => EventLog.DeleteEventSource("", ""));
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void LogDisplayNameDefault()
|
||||
{
|
||||
string source = "Source_" + nameof(LogDisplayNameDefault);
|
||||
string log = "MyLogDisplay";
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
using (EventLog eventlog = new EventLog())
|
||||
{
|
||||
eventlog.Source = source;
|
||||
Assert.Equal(log, eventlog.LogDisplayName);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void GetMessageUsingEventMessageDLL()
|
||||
{
|
||||
if (CultureInfo.CurrentCulture.ToString() != "en-US")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using (EventLog eventlog = new EventLog("Security"))
|
||||
{
|
||||
eventlog.Source = "Security";
|
||||
EventLogEntry eventLogEntry;
|
||||
eventLogEntry = Helpers.RetryOnWin7(() => eventlog.Entries[0]);
|
||||
Assert.Contains("", eventLogEntry.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
404
external/corefx/src/System.Diagnostics.EventLog/tests/EventLogTests/EventLogWriteEntryTests.cs
vendored
Normal file
404
external/corefx/src/System.Diagnostics.EventLog/tests/EventLogTests/EventLogWriteEntryTests.cs
vendored
Normal file
@@ -0,0 +1,404 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.ComponentModel;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Diagnostics.Tests
|
||||
{
|
||||
public class EventLogWriteEntryTests
|
||||
{
|
||||
private const string message = "EventLogWriteEntryTestsMessage";
|
||||
|
||||
private readonly byte[] rawData = new byte[4] { 0, 1, 2, 3 };
|
||||
private readonly EventInstance eventInstance = new EventInstance(0, 1);
|
||||
private readonly string[] insertStrings = { "ExtraText", "MoreText" };
|
||||
|
||||
private EventLogEntry WriteLogEntry(string source, bool type = false, bool instance = false, bool category = false, bool data = false)
|
||||
{
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Source = source;
|
||||
if (instance)
|
||||
{
|
||||
Helpers.RetryOnWin7(() => EventLog.WriteEvent(source, eventInstance));
|
||||
if (data)
|
||||
{
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEntry(message, EventLogEntryType.Warning, (int)eventInstance.InstanceId, (short)eventInstance.CategoryId, rawData));
|
||||
return eventLog.Entries.LastOrDefault();
|
||||
}
|
||||
else if (category)
|
||||
{
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEntry(message, EventLogEntryType.Warning, (int)eventInstance.InstanceId, (short)eventInstance.CategoryId));
|
||||
return eventLog.Entries.LastOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEntry(message, EventLogEntryType.Warning, (int)eventInstance.InstanceId));
|
||||
return eventLog.Entries.LastOrDefault();
|
||||
}
|
||||
}
|
||||
else if (type)
|
||||
{
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEntry(message, EventLogEntryType.Warning));
|
||||
}
|
||||
else
|
||||
{
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEntry(message));
|
||||
}
|
||||
|
||||
return eventLog.Entries.LastOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
private EventLogEntry WriteLogEntryWithSource(string source, bool type = false, bool instance = false, bool category = false, bool data = false)
|
||||
{
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Source = source;
|
||||
if (instance)
|
||||
{
|
||||
Helpers.RetryOnWin7(() => EventLog.WriteEvent(source, eventInstance));
|
||||
if (data)
|
||||
{
|
||||
Helpers.RetryOnWin7(() => EventLog.WriteEntry(source, message, EventLogEntryType.Warning, (int)eventInstance.InstanceId, (short)eventInstance.CategoryId, rawData));
|
||||
return eventLog.Entries.LastOrDefault();
|
||||
}
|
||||
else if (category)
|
||||
{
|
||||
Helpers.RetryOnWin7(() => EventLog.WriteEntry(source, message, EventLogEntryType.Warning, (int)eventInstance.InstanceId, (short)eventInstance.CategoryId));
|
||||
return eventLog.Entries.LastOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
Helpers.RetryOnWin7(() => EventLog.WriteEntry(source, message, EventLogEntryType.Warning, (int)eventInstance.InstanceId));
|
||||
return eventLog.Entries.LastOrDefault();
|
||||
}
|
||||
}
|
||||
else if (type)
|
||||
{
|
||||
Helpers.RetryOnWin7(() => EventLog.WriteEntry(source, message, EventLogEntryType.Warning));
|
||||
}
|
||||
else
|
||||
{
|
||||
Helpers.RetryOnWin7(() => EventLog.WriteEntry(source, message));
|
||||
}
|
||||
|
||||
return eventLog.Entries.LastOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
private EventLogEntry WriteLogEntryEventSource(string source, bool data = false)
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
Helpers.RetryOnWin7(() => EventLog.WriteEvent(source, eventInstance, rawData, insertStrings));
|
||||
}
|
||||
else
|
||||
{
|
||||
Helpers.RetryOnWin7(() => EventLog.WriteEvent(source, eventInstance, insertStrings));
|
||||
}
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
eventLog.Source = source;
|
||||
return eventLog.Entries.LastOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
private EventLogEntry WriteLogEntryEvent(string source, bool data = false)
|
||||
{
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
string[] insertStringsSingleton = { "ExtraText" };
|
||||
eventLog.Source = source;
|
||||
if (data)
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEvent(eventInstance, rawData, insertStringsSingleton));
|
||||
else
|
||||
Helpers.RetryOnWin7(() => eventLog.WriteEvent(eventInstance, insertStringsSingleton));
|
||||
|
||||
return eventLog.Entries.LastOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalTheory(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void WriteEntry(bool sourceFlag)
|
||||
{
|
||||
string log = "Entry";
|
||||
string source = "Source" + nameof(WriteEntry);
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
EventLogEntry eventLogEntry;
|
||||
|
||||
if (sourceFlag)
|
||||
eventLogEntry = WriteLogEntry(source);
|
||||
else
|
||||
eventLogEntry = WriteLogEntryWithSource(source);
|
||||
|
||||
if (eventLogEntry != null)
|
||||
{
|
||||
Assert.Contains(message, eventLogEntry.Message);
|
||||
Assert.Equal(source, eventLogEntry.Source);
|
||||
Assert.StartsWith(Environment.MachineName.ToLowerInvariant(), eventLogEntry.MachineName.ToLowerInvariant());
|
||||
Assert.Equal(eventLogEntry.TimeWritten, eventLogEntry.TimeGenerated);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalTheory(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void WriteEntryWithType(bool sourceFlag)
|
||||
{
|
||||
string source = "Source" + nameof(WriteEntryWithType);
|
||||
string log = "TypeEntry";
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
EventLogEntry eventLogEntry;
|
||||
if (sourceFlag)
|
||||
eventLogEntry = WriteLogEntry(source, type: true);
|
||||
else
|
||||
eventLogEntry = WriteLogEntryWithSource(source, type: true);
|
||||
|
||||
if (eventLogEntry != null)
|
||||
{
|
||||
Assert.Contains(message, eventLogEntry.Message);
|
||||
Assert.Equal(EventLogEntryType.Warning, eventLogEntry.EntryType);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalTheory(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void WriteEntryWithTypeAndId(bool sourceFlag)
|
||||
{
|
||||
string source = "Source" + nameof(WriteEntryWithTypeAndId);
|
||||
string log = "InstanceEntry";
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
EventLogEntry eventLogEntry;
|
||||
if (sourceFlag)
|
||||
eventLogEntry = WriteLogEntry(source, type: true, instance: true);
|
||||
else
|
||||
eventLogEntry = WriteLogEntryWithSource(source, type: true, instance: true);
|
||||
|
||||
if (eventLogEntry != null)
|
||||
{
|
||||
Assert.Contains(message, eventLogEntry.Message);
|
||||
Assert.Equal((int)eventInstance.InstanceId, eventLogEntry.InstanceId);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalTheory(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void WriteEntryWithTypeIdAndCategory(bool sourceFlag)
|
||||
{
|
||||
string source = "Source" + nameof(WriteEntryWithTypeIdAndCategory);
|
||||
string log = "CategoryEntry";
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
EventLogEntry eventLogEntry;
|
||||
if (sourceFlag)
|
||||
eventLogEntry = WriteLogEntry(source, type: true, instance: true, category: true);
|
||||
else
|
||||
eventLogEntry = WriteLogEntryWithSource(source, type: true, instance: true, category: true);
|
||||
|
||||
// There is some prefix string already attached to the message passed
|
||||
// The description for Event ID '0' in Source 'SourceWriteEntryWithTypeIDAndCategory' cannot be found. The local computer may not have the necessary registry information or message DLL files to display the message, or you may not have permission
|
||||
// to access them. The following information is part of the event:'EventLogWriteEntryTestsMessage'
|
||||
// The last part is the associated message
|
||||
// The initial message is due in insufficient permission to access resource library EventLogMsgs.dll
|
||||
if (eventLogEntry != null)
|
||||
{
|
||||
Assert.Contains(message, eventLogEntry.Message);
|
||||
Assert.Equal((short)eventInstance.CategoryId, eventLogEntry.CategoryNumber);
|
||||
Assert.Equal("(" + eventLogEntry.CategoryNumber + ")", eventLogEntry.Category);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalTheory(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void WriteEntryWithTypeIdCategoryAndData(bool sourceFlag)
|
||||
{
|
||||
string source = "Source" + nameof(WriteEntryWithTypeIdCategoryAndData);
|
||||
string log = "EntryData";
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
EventLogEntry eventLogEntry;
|
||||
if (sourceFlag)
|
||||
eventLogEntry = WriteLogEntry(source, type: true, instance: true, category: true, data: true);
|
||||
else
|
||||
eventLogEntry = WriteLogEntryWithSource(source, type: true, instance: true, category: true, data: true);
|
||||
|
||||
if (eventLogEntry != null)
|
||||
{
|
||||
Assert.Contains(message, eventLogEntry.Message);
|
||||
Assert.Equal(rawData, eventLogEntry.Data);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalTheory(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void WriteEntryWithoutSource()
|
||||
{
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => eventLog.WriteEntry(message));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalTheory(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void WriteEntryWithInvalidType()
|
||||
{
|
||||
using (EventLog eventLog = new EventLog())
|
||||
{
|
||||
string source = "Source_" + nameof(WriteEntryWithInvalidType);
|
||||
eventLog.Source = source;
|
||||
Assert.Throws<InvalidEnumArgumentException>(() => eventLog.WriteEntry(message, (EventLogEntryType)7)); // 7 is a random number which is not associated with any type in EventLogEntryType
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalTheory(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void WriteEntryWithNullOrEmptySource()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => EventLog.WriteEntry(null, message));
|
||||
Assert.Throws<ArgumentException>(() => EventLog.WriteEntry("", message));
|
||||
}
|
||||
|
||||
[ConditionalTheory(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void WriteEvent(bool SourceFlag)
|
||||
{
|
||||
string source = "Source_" + nameof(WriteEvent);
|
||||
string log = "Event";
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
EventLogEntry eventLogEntry;
|
||||
if (SourceFlag)
|
||||
eventLogEntry = WriteLogEntryEventSource(source);
|
||||
else
|
||||
eventLogEntry = WriteLogEntryEvent(source);
|
||||
|
||||
if (eventLogEntry != null)
|
||||
Assert.All(insertStrings, message => eventLogEntry.Message.Contains(message));
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalTheory(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void WriteEventWithData(bool SourceFlag)
|
||||
{
|
||||
string log = "EventData";
|
||||
string source = "Source_" + nameof(WriteEventWithData);
|
||||
try
|
||||
{
|
||||
EventLog.CreateEventSource(source, log);
|
||||
EventLogEntry eventLogEntry;
|
||||
|
||||
if (SourceFlag)
|
||||
eventLogEntry = WriteLogEntryEventSource(source, data: true);
|
||||
else
|
||||
eventLogEntry = WriteLogEntryEvent(source, data: true);
|
||||
|
||||
if (eventLogEntry != null)
|
||||
Assert.Equal(rawData, eventLogEntry.Data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
Helpers.RetryOnWin7(() => EventLog.Delete(log));
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalTheory(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void WriteEventInstanceNull()
|
||||
{
|
||||
string source = "Source_" + nameof(WriteEventInstanceNull);
|
||||
Assert.Throws<ArgumentNullException>(() => Helpers.RetryOnWin7(() => EventLog.WriteEvent(source, null, insertStrings)));
|
||||
}
|
||||
|
||||
[ConditionalTheory(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void WriteEventMessageValues_OutOfRange()
|
||||
{
|
||||
string source = "Source_" + nameof(WriteEventMessageValues_OutOfRange);
|
||||
string[] message = new string[1];
|
||||
message[0] = new string('c', 32767);
|
||||
Assert.Throws<ArgumentException>(() => Helpers.RetryOnWin7(() => EventLog.WriteEvent(source, eventInstance, message)));
|
||||
}
|
||||
|
||||
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void WriteWithoutExistingSource()
|
||||
{
|
||||
string source = "Source_" + nameof(WriteWithoutExistingSource);
|
||||
try
|
||||
{
|
||||
Helpers.RetryOnWin7(() => EventLog.WriteEvent(source, eventInstance, rawData, null));
|
||||
Assert.Equal("Application", EventLog.LogNameFromSourceName(source, "."));
|
||||
}
|
||||
finally
|
||||
{
|
||||
EventLog.DeleteEventSource(source);
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalTheory(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
|
||||
public void SourceNameMaxLengthExceeded()
|
||||
{
|
||||
string source = new string('s', 254);
|
||||
Assert.Throws<ArgumentException>(() => EventLog.WriteEntry(source, message));
|
||||
}
|
||||
}
|
||||
|
||||
internal static class EventLogEntryCollectionExtensions
|
||||
{
|
||||
internal static EventLogEntry LastOrDefault(this EventLogEntryCollection elec)
|
||||
{
|
||||
return Helpers.RetryOnWin7(() => elec.Count > 0 ? elec[elec.Count - 1] : null);
|
||||
}
|
||||
}
|
||||
}
|
86
external/corefx/src/System.Diagnostics.EventLog/tests/Helpers.cs
vendored
Normal file
86
external/corefx/src/System.Diagnostics.EventLog/tests/Helpers.cs
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Threading;
|
||||
using Xunit;
|
||||
|
||||
// Implementation is not robust with respect to concurrently writing and reading log
|
||||
[assembly: CollectionBehavior(DisableTestParallelization = true)]
|
||||
|
||||
namespace System.Diagnostics.Tests
|
||||
{
|
||||
internal class Helpers
|
||||
{
|
||||
public static bool IsElevatedAndSupportsEventLogs { get => AdminHelpers.IsProcessElevated() && SupportsEventLogs; }
|
||||
public static bool SupportsEventLogs { get => PlatformDetection.IsNotWindowsNanoServer; }
|
||||
|
||||
public static void RetryOnWin7(Action func)
|
||||
{
|
||||
RetryOnWin7<object>(() => { func(); return null; });
|
||||
}
|
||||
|
||||
public static T RetryOnWin7<T>(Func<T> func)
|
||||
{
|
||||
if (!PlatformDetection.IsWindows7)
|
||||
{
|
||||
return func();
|
||||
}
|
||||
|
||||
return RetryOnAllPlatforms(func);
|
||||
// We are retrying on windows 7 because it throws win32exception while some operations like Writing,retrieving and Deleting log.
|
||||
// So We just try to do the operation again in case of this exception
|
||||
}
|
||||
|
||||
public static T RetryOnAllPlatforms<T>(Func<T> func)
|
||||
{
|
||||
T entry = default(T);
|
||||
int retries = 20;
|
||||
while (retries > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
entry = func();
|
||||
retries = -1;
|
||||
}
|
||||
catch (Win32Exception)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
retries--;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
retries--;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.NotEqual(0, retries);
|
||||
return entry;
|
||||
}
|
||||
|
||||
public static void WaitForEventLog(EventLog eventLog, int entriesExpected)
|
||||
{
|
||||
int tries = 1;
|
||||
Stopwatch stopwatch = Stopwatch.StartNew();
|
||||
while (RetryOnAllPlatforms((() => eventLog.Entries.Count)) < entriesExpected && tries <= 50)
|
||||
{
|
||||
if (tries == 50)
|
||||
{
|
||||
Thread.Sleep(30000);
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(100 * (tries));
|
||||
}
|
||||
tries++;
|
||||
}
|
||||
|
||||
if (stopwatch.ElapsedMilliseconds / 1000 >= 5)
|
||||
Console.WriteLine($"{stopwatch.ElapsedMilliseconds / 1000 } seconds");
|
||||
|
||||
Assert.Equal(entriesExpected, RetryOnWin7((() => eventLog.Entries.Count)));
|
||||
}
|
||||
}
|
||||
}
|
@@ -9,8 +9,13 @@
|
||||
<ProjectGuid>{5B218883-369E-4C3D-8BD0-74843474DCBD}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="EventInstanceTests.cs" />
|
||||
<Compile Include="EventLogEntryCollectionTests.cs" />
|
||||
<Compile Include="EventLogTests\EventLogEntryWrittenTest.cs" />
|
||||
<Compile Include="EventLogTests\EventLogSourceCreationTests.cs" />
|
||||
<Compile Include="EventLogTests\EventLogTests.cs" />
|
||||
<Compile Include="EventLogTests\EventLogWriteEntryTests.cs" />
|
||||
<Compile Include="Helpers.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
Reference in New Issue
Block a user