A
Azhar Desai
Guest
I am trying to read windows logs of the remote machine using .NET Core 3.0.0-preview8 version as the documents supports EventLogSession from .NET Core 3.0.0-preview8. But when I am running the sample code snippet to create a session from EventLogSession it failed at runtime below is the stacktrace
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at System.Diagnostics.Eventing.Reader.EventLogPermissionHolder.GetEventLogPermission()
at System.Diagnostics.Eventing.Reader.EventLogSession..ctor(String server, String domain, String user, SecureString password, SessionAuthentication logOnType)
at WincTest1.Program.Main(String[] args) in D:\JIRA\Framework\WincModernisation\WincTest1\Program.cs:line 37
Below is the code snippet
using System;
using System.Diagnostics;
using System.Threading;
using System.Diagnostics.Eventing.Reader;
using System.Security;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks.Dataflow;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Text.RegularExpressions;
namespace WincTest1
{
class Program
{
static void Main(string[] args)
{
String password = "Password";
SecureString securePassword = null;
char[] passwordArr;
if (password != null)
{
securePassword = new SecureString();
passwordArr = password.ToCharArray();
for (int i = 0; i < passwordArr.Length; i++)
{
securePassword.AppendChar(passwordArr);
}
}
EventLogSession session = new EventLogSession("127.0.0.1", "domain", "username", securePassword, SessionAuthentication.Default);
Console.WriteLine("Log name " + session.GetLogNames());
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Core" Version="3.5.21022.801" />
<PackageReference Include="System.Diagnostics.EventLog" Version="4.5.0" />
<PackageReference Include="TaskScheduler" Version="2.8.15" />
</ItemGroup>
</Project>
Continue reading...
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at System.Diagnostics.Eventing.Reader.EventLogPermissionHolder.GetEventLogPermission()
at System.Diagnostics.Eventing.Reader.EventLogSession..ctor(String server, String domain, String user, SecureString password, SessionAuthentication logOnType)
at WincTest1.Program.Main(String[] args) in D:\JIRA\Framework\WincModernisation\WincTest1\Program.cs:line 37
Below is the code snippet
using System;
using System.Diagnostics;
using System.Threading;
using System.Diagnostics.Eventing.Reader;
using System.Security;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks.Dataflow;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Text.RegularExpressions;
namespace WincTest1
{
class Program
{
static void Main(string[] args)
{
String password = "Password";
SecureString securePassword = null;
char[] passwordArr;
if (password != null)
{
securePassword = new SecureString();
passwordArr = password.ToCharArray();
for (int i = 0; i < passwordArr.Length; i++)
{
securePassword.AppendChar(passwordArr);
}
}
EventLogSession session = new EventLogSession("127.0.0.1", "domain", "username", securePassword, SessionAuthentication.Default);
Console.WriteLine("Log name " + session.GetLogNames());
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Core" Version="3.5.21022.801" />
<PackageReference Include="System.Diagnostics.EventLog" Version="4.5.0" />
<PackageReference Include="TaskScheduler" Version="2.8.15" />
</ItemGroup>
</Project>
Continue reading...