Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated SwqlStudio.csproj to use Serilog for logging #275

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 53 additions & 47 deletions Src/Contract/InfoServiceProxy.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Data;
using System.Data.Common;
using System.ServiceModel;
using Microsoft.Extensions.Logging;
using SolarWinds.InformationService.Contract2;

namespace SolarWinds.InformationService.InformationServiceClient
Expand All @@ -15,78 +16,17 @@ public sealed class InformationServiceConnection : DbConnection
private string remoteAddress;
private InfoServiceProxy proxy;
private ServiceCredentials credentials;
private readonly ILoggerFactory _loggerFactory;
private readonly bool bProxyOwner = true;
private bool open = false;

public InformationServiceConnection()
: this(string.Empty)
public InformationServiceConnection(ILoggerFactory loggerFactory, IInformationService service)
{
}

public InformationServiceConnection(string endpointName)
{
if (endpointName == null)
throw new ArgumentNullException(nameof(endpointName));

Initialize(endpointName, null, null);
}

//This is required by NCM. NCM provide it's own proxy object
public InformationServiceConnection(InfoServiceProxy proxy) : this(proxy, false)
{
}

public InformationServiceConnection(InfoServiceProxy proxy, bool takeOwnership)
{
Service = proxy;
bProxyOwner = takeOwnership;
if (bProxyOwner)
{
this.proxy = proxy;
}
}

public InformationServiceConnection(IInformationService service)
{
if (service == null)
throw new ArgumentNullException(nameof(service));

Service = service;
_loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
Service = service ?? throw new ArgumentNullException(nameof(service));
bProxyOwner = false;
}

public InformationServiceConnection(string endpointName, string remoteAddress)
{
if (endpointName == null)
throw new ArgumentNullException(nameof(endpointName));
if (remoteAddress == null)
throw new ArgumentNullException(nameof(remoteAddress));

Initialize(endpointName, remoteAddress, null);
}

public InformationServiceConnection(string endpointName, string remoteAddress, ServiceCredentials credentials)
{
if (endpointName == null)
throw new ArgumentNullException(nameof(endpointName));
if (remoteAddress == null)
throw new ArgumentNullException(nameof(remoteAddress));
if (credentials == null)
throw new ArgumentNullException(nameof(credentials));

Initialize(endpointName, remoteAddress, credentials);
}

public InformationServiceConnection(string endpointName, ServiceCredentials credentials)
{
if (endpointName == null)
throw new ArgumentNullException(nameof(endpointName));
if (credentials == null)
throw new ArgumentNullException(nameof(credentials));

Initialize(endpointName, null, credentials);
}

protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
{
throw new NotSupportedException();
Expand Down Expand Up @@ -241,19 +181,21 @@ private void CreateProxy()
{
if (endpointName.Length != 0)
{
ILogger<InfoServiceProxy> logger = _loggerFactory.CreateLogger<InfoServiceProxy>();

if (remoteAddress != null)
{
if (credentials != null)
proxy = new InfoServiceProxy(endpointName, remoteAddress, credentials);
proxy = new InfoServiceProxy(logger, endpointName, remoteAddress, credentials);
else
proxy = new InfoServiceProxy(endpointName, remoteAddress);
proxy = new InfoServiceProxy(logger, endpointName, remoteAddress);
}
else
{
if (credentials != null)
proxy = new InfoServiceProxy(endpointName, credentials);
proxy = new InfoServiceProxy(logger, endpointName, credentials);
else
proxy = new InfoServiceProxy(endpointName);
proxy = new InfoServiceProxy(logger, endpointName);
}

Service = proxy;
Expand Down
7 changes: 5 additions & 2 deletions Src/Contract/InformationServiceContext.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using System;
using Microsoft.Extensions.Logging;

namespace SolarWinds.InformationService.Contract2
{
public class InformationServiceContext : IDisposable
{
private bool disposed = false;
private readonly ILoggerFactory _loggerFactory;
private readonly IInformationService service = null;

public InformationServiceContext(IInformationService service)
public InformationServiceContext(ILoggerFactory loggerFactory, IInformationService service)
{
_loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
this.service = service;
}

Expand All @@ -26,7 +29,7 @@ public InformationServiceContext(IInformationService service)
if (disposed)
throw new InvalidOperationException("context disposed");

return new InformationServiceQuery<T>(this, queryString);
return new InformationServiceQuery<T>(_loggerFactory.CreateLogger<InformationServiceQuery<T>>(), this, queryString);
}

public InfoServiceProxy Proxy { get; private set; } = null;
Expand Down
10 changes: 6 additions & 4 deletions Src/Contract/InformationServiceQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Xml;
using SolarWinds.Logging;
using Microsoft.Extensions.Logging;

namespace SolarWinds.InformationService.Contract2
{
public class InformationServiceQuery : IDisposable
{
private static readonly Log log = new Log();
private readonly ILogger<InformationServiceQuery> log;

private readonly InformationServiceContext context;
private readonly string queryString;
Expand All @@ -19,8 +19,10 @@ public class InformationServiceQuery : IDisposable

protected bool disposed = false;

public InformationServiceQuery(InformationServiceContext context, string queryString, PropertyBag parameters)
public InformationServiceQuery(ILogger<InformationServiceQuery> logger, InformationServiceContext context, string queryString, PropertyBag parameters)
{
log = logger ?? throw new ArgumentNullException(nameof(logger));

if (context == null)
throw new ArgumentNullException(nameof(context));
if (queryString == null)
Expand All @@ -47,7 +49,7 @@ public XmlReader Execute(bool hierarchical)

Message response = context.Service.Query(request);

log.Debug(response);
log.LogDebug(response.ToString());

if (response.IsFault)
{
Expand Down
9 changes: 5 additions & 4 deletions Src/Contract/InformationServiceQueryOfT.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Xml;
using Microsoft.Extensions.Logging;

namespace SolarWinds.InformationService.Contract2
{
Expand All @@ -9,13 +10,13 @@ namespace SolarWinds.InformationService.Contract2
private readonly Type type = typeof(T);
private readonly IResponseParser<T> parser;

public InformationServiceQuery(InformationServiceContext context, string queryString)
: this(context, queryString, null)
public InformationServiceQuery(ILogger<InformationServiceQuery<T>> logger, InformationServiceContext context, string queryString)
: this(logger, context, queryString, null)
{
}

public InformationServiceQuery(InformationServiceContext context, string query, PropertyBag parameters)
: base(context, query, parameters)
public InformationServiceQuery(ILogger<InformationServiceQuery<T>> logger, InformationServiceContext context, string query, PropertyBag parameters)
: base(logger, context, query, parameters)
{
object[] attributes = type.GetCustomAttributes(typeof(InformationServiceEntityAttribute), false);

Expand Down
11 changes: 1 addition & 10 deletions Src/Contract/SolarWinds.InformationService.Contract.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,14 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Logging\SolarWinds.Logging.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="System.ServiceModel.Duplex" Version="4.7.0" />
<PackageReference Include="System.ServiceModel.Http" Version="4.7.0" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.7.0" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.7.0" />
<PackageReference Include="System.ServiceModel.Security" Version="4.7.0" />
</ItemGroup>

<!--<ItemGroup>
<Reference Include="System.configuration" />
<Reference Include="System.IdentityModel" />
<Reference Include="System.ServiceModel" />
</ItemGroup>-->

<ItemGroup>
<Compile Update="InformationServiceClient\InformationServiceCommand.cs" />
<Compile Update="InformationServiceClient\InformationServiceConnection.cs" />
Expand Down
51 changes: 45 additions & 6 deletions Src/Install/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,25 @@
<Component Id="SwqlStudioComponent" Guid="BC0A98E5-219C-4d5a-9A14-A10A13546DB8">
<File Id="SwqlStudioExe" Source="$(var.OutputDir)\SwqlStudio.exe" />
<File Source="$(var.OutputDir)\SwqlStudio.exe.config" />
<File Source="$(var.OutputDir)\log4net.dll" />
<File Source="$(var.OutputDir)\Microsoft.Bcl.AsyncInterfaces.dll" />
<File Source="$(var.OutputDir)\Microsoft.Extensions.DependencyInjection.Abstractions.dll" />
<File Source="$(var.OutputDir)\Microsoft.Extensions.DependencyInjection.dll" />
<File Source="$(var.OutputDir)\Microsoft.Extensions.Logging.Abstractions.dll" />
<File Source="$(var.OutputDir)\Microsoft.Extensions.Logging.dll" />
<File Source="$(var.OutputDir)\Microsoft.Extensions.Options.dll" />
<File Source="$(var.OutputDir)\Microsoft.Extensions.Primitives.dll" />
<File Source="$(var.OutputDir)\ScintillaNet.dll" />
<File Source="$(var.OutputDir)\Serilog.dll" />
<File Source="$(var.OutputDir)\Serilog.Extensions.Logging.dll" />
<File Source="$(var.OutputDir)\Serilog.Sinks.File.dll" />
<File Source="$(var.OutputDir)\SolarWinds.SDK.Swis.Contract.dll" />
<File Source="$(var.OutputDir)\SolarWinds.Logging.dll" />
<File Source="$(var.OutputDir)\System.Buffers.dll" />
<File Source="$(var.OutputDir)\Security.Cryptography.dll" />
<File Source="$(var.OutputDir)\System.Configuration.ConfigurationManager.dll" />
<File Source="$(var.OutputDir)\System.Diagnostics.DiagnosticSource.dll" />
<File Source="$(var.OutputDir)\System.Memory.dll" />
<File Source="$(var.OutputDir)\System.Numerics.Vectors.dll" />
<File Source="$(var.OutputDir)\System.Runtime.CompilerServices.Unsafe.dll" />
<File Source="$(var.OutputDir)\System.Security.AccessControl.dll" />
<File Source="$(var.OutputDir)\System.Security.Permissions.dll" />
<File Source="$(var.OutputDir)\System.Security.Principal.Windows.dll" />
Expand All @@ -133,6 +146,8 @@
<File Source="$(var.OutputDir)\System.ServiceModel.NetTcp.dll" />
<File Source="$(var.OutputDir)\System.ServiceModel.Primitives.dll" />
<File Source="$(var.OutputDir)\System.ServiceModel.Security.dll" />
<File Source="$(var.OutputDir)\System.Threading.Tasks.Extensions.dll" />
<File Source="$(var.OutputDir)\System.ValueTuple.dll" />
<File Source="$(var.OutputDir)\WeifenLuo.WinFormsUI.Docking.dll" />
<File Source="$(var.OutputDir)\WeifenLuo.WinFormsUI.Docking.ThemeVS2015.dll" />
</Component>
Expand All @@ -152,11 +167,21 @@
<Directory Id="SwisPowerShell" Name="SwisPowerShell">
<Directory Id="psm_Version" Name="$(var.BuildNumber)">
<Component Id="SwisPowerShellModule" Guid="077E4881-0A55-4646-BF7A-25F1B084348B">
<File Id="psm_Microsoft.Bcl.AsyncInterfaces.dll" Source="$(var.OutputDir)\Microsoft.Bcl.AsyncInterfaces.dll" />
<File Id="psm_Microsoft.Extensions.DependencyInjection.Abstractions.dll" Source="$(var.OutputDir)\Microsoft.Extensions.DependencyInjection.Abstractions.dll" />
<File Id="psm_Microsoft.Extensions.DependencyInjection.dll" Source="$(var.OutputDir)\Microsoft.Extensions.DependencyInjection.dll" />
<File Id="psm_Microsoft.Extensions.Logging.Abstractions.dll" Source="$(var.OutputDir)\Microsoft.Extensions.Logging.Abstractions.dll" />
<File Id="psm_Microsoft.Extensions.Logging.dll" Source="$(var.OutputDir)\Microsoft.Extensions.Logging.dll" />
<File Id="psm_Microsoft.Extensions.Options.dll" Source="$(var.OutputDir)\Microsoft.Extensions.Options.dll" />
<File Id="psm_Microsoft.Extensions.Primitives.dll" Source="$(var.OutputDir)\Microsoft.Extensions.Primitives.dll" />
<File Id="psm_SwisPowerShellDll" Source="..\SwisPowerShell\bin\Release\SwisPowerShell.dll" />
<File Id="psm_SwisPowerShell.psd1" Source="..\SwisPowerShell\bin\Release\SwisPowerShell.psd1" />
<File Id="psm_SolarWinds.SDK.Swis.Contract.dll" Source="$(var.OutputDir)\SolarWinds.SDK.Swis.Contract.dll" />
<File Id="psm_log4net.dll" Source="$(var.OutputDir)\log4net.dll" />
<File Id="psm_SolarWinds.Logging.dll" Source="$(var.OutputDir)\SolarWinds.Logging.dll" />
<File Id="psm_System.Buffers.dll" Source="$(var.OutputDir)\System.Buffers.dll" />
<File Id="psm_System.Diagnostics.DiagnosticSource.dll" Source="$(var.OutputDir)\System.Diagnostics.DiagnosticSource.dll" />
<File Id="psm_System.Memory.dll" Source="$(var.OutputDir)\System.Memory.dll" />
<File Id="psm_System.Numerics.Vectors.dll" Source="$(var.OutputDir)\System.Numerics.Vectors.dll" />
<File Id="psm_System.Runtime.CompilerServices.Unsafe.dll" Source="$(var.OutputDir)\System.Runtime.CompilerServices.Unsafe.dll" />
<File Id="psm_System.Security.AccessControl.dll" Source="$(var.OutputDir)\System.Security.AccessControl.dll" />
<File Id="psm_System.Security.Permissions.dll" Source="$(var.OutputDir)\System.Security.Permissions.dll" />
<File Id="psm_System.Security.Principal.Windows.dll" Source="$(var.OutputDir)\System.Security.Principal.Windows.dll" />
Expand All @@ -165,6 +190,8 @@
<File Id="psm_System.ServiceModel.NetTcp.dll" Source="$(var.OutputDir)\System.ServiceModel.NetTcp.dll" />
<File Id="psm_System.ServiceModel.Primitives.dll" Source="$(var.OutputDir)\System.ServiceModel.Primitives.dll" />
<File Id="psm_System.ServiceModel.Security.dll" Source="$(var.OutputDir)\System.ServiceModel.Security.dll" />
<File Id="psm_System.Threading.Tasks.Extensions.dll" Source="$(var.OutputDir)\System.Threading.Tasks.Extensions.dll" />
<File Id="psm_System.ValueTuple.dll" Source="$(var.OutputDir)\System.ValueTuple.dll" />
</Component>
</Directory>
</Directory>
Expand All @@ -178,11 +205,21 @@
<Directory Id="SwisPowerShell64" Name="SwisPowerShell">
<Directory Id="psm64_Version" Name="$(var.BuildNumber)">
<Component Id="SwisPowerShellModule64" Win64="yes" Guid="8618CFEC-57A9-4C6D-8128-6D204B13015A">
<File Id="psm64_Microsoft.Bcl.AsyncInterfaces.dll" Source="$(var.OutputDir)\Microsoft.Bcl.AsyncInterfaces.dll" />
<File Id="psm64_Microsoft.Extensions.DependencyInjection.Abstractions.dll" Source="$(var.OutputDir)\Microsoft.Extensions.DependencyInjection.Abstractions.dll" />
<File Id="psm64_Microsoft.Extensions.DependencyInjection.dll" Source="$(var.OutputDir)\Microsoft.Extensions.DependencyInjection.dll" />
<File Id="psm64_Microsoft.Extensions.Logging.Abstractions.dll" Source="$(var.OutputDir)\Microsoft.Extensions.Logging.Abstractions.dll" />
<File Id="psm64_Microsoft.Extensions.Logging.dll" Source="$(var.OutputDir)\Microsoft.Extensions.Logging.dll" />
<File Id="psm64_Microsoft.Extensions.Options.dll" Source="$(var.OutputDir)\Microsoft.Extensions.Options.dll" />
<File Id="psm64_Microsoft.Extensions.Primitives.dll" Source="$(var.OutputDir)\Microsoft.Extensions.Primitives.dll" />
<File Id="psm64_SwisPowerShellDll" Source="..\SwisPowerShell\bin\Release\SwisPowerShell.dll" />
<File Id="psm64_SwisPowerShell.psd1" Source="..\SwisPowerShell\bin\Release\SwisPowerShell.psd1" />
<File Id="psm64_SolarWinds.SDK.Swis.Contract.dll" Source="$(var.OutputDir)\SolarWinds.SDK.Swis.Contract.dll" />
<File Id="psm64_log4net.dll" Source="$(var.OutputDir)\log4net.dll" />
<File Id="psm64_SolarWinds.Logging.dll" Source="$(var.OutputDir)\SolarWinds.Logging.dll" />
<File Id="psm64_System.Buffers.dll" Source="$(var.OutputDir)\System.Buffers.dll" />
<File Id="psm64_System.Diagnostics.DiagnosticSource.dll" Source="$(var.OutputDir)\System.Diagnostics.DiagnosticSource.dll" />
<File Id="psm64_System.Memory.dll" Source="$(var.OutputDir)\System.Memory.dll" />
<File Id="psm64_System.Numerics.Vectors.dll" Source="$(var.OutputDir)\System.Numerics.Vectors.dll" />
<File Id="psm64_System.Runtime.CompilerServices.Unsafe.dll" Source="$(var.OutputDir)\System.Runtime.CompilerServices.Unsafe.dll" />
<File Id="psm64_System.Security.AccessControl.dll" Source="$(var.OutputDir)\System.Security.AccessControl.dll" />
<File Id="psm64_System.Security.Permissions.dll" Source="$(var.OutputDir)\System.Security.Permissions.dll" />
<File Id="psm64_System.Security.Principal.Windows.dll" Source="$(var.OutputDir)\System.Security.Principal.Windows.dll" />
Expand All @@ -191,6 +228,8 @@
<File Id="psm64_System.ServiceModel.NetTcp.dll" Source="$(var.OutputDir)\System.ServiceModel.NetTcp.dll" />
<File Id="psm64_System.ServiceModel.Primitives.dll" Source="$(var.OutputDir)\System.ServiceModel.Primitives.dll" />
<File Id="psm64_System.ServiceModel.Security.dll" Source="$(var.OutputDir)\System.ServiceModel.Security.dll" />
<File Id="psm64_System.Threading.Tasks.Extensions.dll" Source="$(var.OutputDir)\System.Threading.Tasks.Extensions.dll" />
<File Id="psm64_System.ValueTuple.dll" Source="$(var.OutputDir)\System.ValueTuple.dll" />
</Component>
</Directory>
</Directory>
Expand Down
Loading