Skip to content

Commit

Permalink
Merge pull request #61 from difi/common_logging
Browse files Browse the repository at this point in the history
Fra Log4net til Common logging
  • Loading branch information
kristianenge committed May 18, 2016
2 parents f5dc9ab + 38bf56d commit c707ca6
Show file tree
Hide file tree
Showing 23 changed files with 168 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
<HintPath>..\packages\difi-felles-utility-dotnet.0.5.5970.18522\lib\net45\Difi.Felles.Utility.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="log4net, Version=1.2.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.4\lib\net45-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
Expand All @@ -68,7 +64,7 @@
<Compile Include="Entiteter\Svar\PersonerSvar.cs" />
<Compile Include="Entiteter\Svar\PrintSertifikatSvar.cs" />
<Compile Include="Exceptions\SendException.cs" />
<Compile Include="Exceptions\SoapException.cs" />
<Compile Include="Exceptions\UventetFeilException.cs" />
<Compile Include="Exceptions\ValidationException.cs" />
<Compile Include="Exceptions\XmlParseException.cs" />
<Compile Include="Entiteter\Kontaktinformasjon.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace Difi.Oppslagstjeneste.Klient.Domene.Exceptions
{
public class SoapException : DifiException
public class UventetFeilException : DifiException
{
public SoapException(XmlDocument outerXml)
public UventetFeilException(XmlDocument outerXml)
: this(outerXml, null)
{
}

public SoapException(XmlDocument xml, Exception innerException)
public UventetFeilException(XmlDocument xml, Exception innerException)
: base("Sjekk klassemedlemmer for mer detaljer.", innerException)
{
ParseToClassMembers(xml);
Expand Down
1 change: 0 additions & 1 deletion Difi.Oppslagstjeneste.Klient.Domene/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
<packages>
<package id="api-client-shared" version="1.0.5941.27271" targetFramework="net45" />
<package id="difi-felles-utility-dotnet" version="0.5.5970.18522" targetFramework="net45" />
<package id="log4net" version="2.0.4" targetFramework="net45" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
<HintPath>..\packages\api-client-shared.1.0.5941.27271\lib\net45\ApiClientShared.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Common.Logging, Version=3.3.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<HintPath>..\packages\Common.Logging.3.3.1\lib\net40\Common.Logging.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Common.Logging.Core, Version=3.3.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<HintPath>..\packages\Common.Logging.Core.3.3.1\lib\net40\Common.Logging.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Difi.Felles.Utility, Version=0.5.5970.18522, Culture=neutral, PublicKeyToken=683b8efceae684a6, processorArchitecture=MSIL">
<HintPath>..\packages\difi-felles-utility-dotnet.0.5.5970.18522\lib\net45\Difi.Felles.Utility.dll</HintPath>
<Private>True</Private>
Expand All @@ -55,10 +63,6 @@
<HintPath>..\packages\CompareNETObjects.3.04.0.0\lib\net45\KellermanSoftware.Compare-NET-Objects.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="log4net, Version=1.2.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.4\lib\net45-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
Expand Down Expand Up @@ -89,7 +93,6 @@
<Compile Include="Fakes\FakeHttpClientHandlerResponse.cs" />
<Compile Include="Smoke\SmokeTests.cs" />
<Compile Include="OppslagstjenesteHelperTests.cs" />
<Compile Include="Properties\AssemblyInfo.log4net.cs" />
<Compile Include="Svar\ResponseContainerTests.cs" />
<Compile Include="Utilities\CompareObjects\Comparator.cs" />
<Compile Include="Utilities\CompareObjects\Difference.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void ParseSoapExceptionSuksess(TestContext context)
const string expectedDescription = "Invalid service usage: Service owner 988015814 does not have access to ENDRINGSTJENESTEN";

//Act
var exception = new SoapException(XmlResource.Response.GetSoapFault());
var exception = new UventetFeilException(XmlResource.Response.GetSoapFault());

//Assert
Assert.AreEqual(expectedGuilty, exception.Skyldig.Trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public void OppslagstjenesteKlientHandlesGenericSoapFaultCorrectly()
var exception = e.InnerExceptions.ElementAt(0);

//Assert
Assert.IsTrue(exception.GetType() == typeof (SoapException));
var soapException = exception as SoapException;
Assert.IsTrue(exception.GetType() == typeof (UventetFeilException));
var soapException = exception as UventetFeilException;
Assert.AreEqual("env:Sender", soapException.Skyldig);
Assert.AreEqual("Invalid service usage: Service owner 988015814 does not have access to ENDRINGSTJENESTEN", soapException.Beskrivelse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class ConstructorMethod : OppslagstjenesteKonfigurasjonTests
public void InitializesFields()
{
//Arrange
const bool forventetLoggForespørselOgRespons = false;
var environment = Miljø.FunksjoneltTestmiljøVerifikasjon1;
var senderUnitTestCertificate = DomainUtility.GetSenderUnitTestCertificate();
var oppslagstjenesteConfiguration = new OppslagstjenesteKonfigurasjon(environment, senderUnitTestCertificate);
Expand All @@ -22,6 +23,7 @@ public void InitializesFields()
//Assert
Assert.AreEqual(environment, oppslagstjenesteConfiguration.Miljø);
Assert.AreEqual(senderUnitTestCertificate, oppslagstjenesteConfiguration.Avsendersertifikat);
Assert.AreEqual( forventetLoggForespørselOgRespons, oppslagstjenesteConfiguration.LoggForespørselOgRespons);
}
}
}
Expand Down

This file was deleted.

3 changes: 1 addition & 2 deletions Difi.Oppslagstjeneste.Klient.Tester/Smoke/SmokeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Threading.Tasks;
using Difi.Oppslagstjeneste.Klient.Domene.Entiteter.Enums;
using Difi.Oppslagstjeneste.Klient.Resources.Certificate;
using log4net.Config;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Difi.Oppslagstjeneste.Klient.Tests.Smoke
Expand All @@ -15,7 +14,7 @@ public class SmokeTests
[ClassInitialize]
public static void Init(TestContext context)
{
XmlConfigurator.Configure();

var senderCertificate = CertificateResource.GetDifiTestCertificate();
var oppslagstjenesteConfiguration = new OppslagstjenesteKonfigurasjon(Miljø.FunksjoneltTestmiljøVerifikasjon1, senderCertificate);

Expand Down
3 changes: 2 additions & 1 deletion Difi.Oppslagstjeneste.Klient.Tester/packages.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="api-client-shared" version="1.0.5941.27271" targetFramework="net45" />
<package id="Common.Logging" version="3.3.1" targetFramework="net45" />
<package id="Common.Logging.Core" version="3.3.1" targetFramework="net45" />
<package id="CompareNETObjects" version="3.04.0.0" targetFramework="net45" />
<package id="CompareObjects" version="1.0.2" targetFramework="net45" />
<package id="difi-felles-utility-dotnet" version="0.5.5970.18522" targetFramework="net45" />
<package id="log4net" version="2.0.4" targetFramework="net45" />
<package id="Moq" version="4.2.1510.2205" targetFramework="net45" />
</packages>
64 changes: 64 additions & 0 deletions Difi.Oppslagstjeneste.Klient.Testklient/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net1213">
<arg key="configType" value="INLINE" />
</factoryAdapter>
<!--<factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
<arg key="level" value="ALL" />
<arg key="showLogName" value="false" />
<arg key="showDataTime" value="false" />
<arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
</factoryAdapter>-->
</logging>
</common>

<log4net>
<logger name="Difi.Oppslagstjeneste.Klient">
<appender-ref ref="RollingFileAppender" />
<level value="DEBUG" />
</logger>
<logger name="Difi.Oppslagstjeneste.RequestLog">
<appender-ref ref="RequestRollingAppender" />
<level value="DEBUG" />
</logger>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<file value="${AppData}\Difi\Log\" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<staticLogFileName value="false" />
<rollingStyle value="Composite" />
<param name="maxSizeRollBackups" value="10" />
<datePattern value="yyyy.MM.dd' Difi.Oppslagstjeneste-klient-dotnet.log'" />
<maximumFileSize value="100MB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5lev - %message%newline" />
</layout>
</appender>
<appender name="RequestRollingAppender" type="log4net.Appender.RollingFileAppender">
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<file value="${AppData}\Difi\RequestLog\" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<staticLogFileName value="false" />
<rollingStyle value="Composite" />
<param name="maxSizeRollBackups" value="10" />
<datePattern value="yyyy.MM.dd' Difi.Oppslagstjeneste-klient-dotnet.log'" />
<maximumFileSize value="100MB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5lev - %message%newline" />
</layout>
</appender>
</log4net>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="KellermanSoftware.Compare-NET-Objects, Version=1.7.4.0, Culture=neutral, PublicKeyToken=d970ace04cc85217, processorArchitecture=MSIL">
<HintPath>..\packages\CompareObjects.1.0.2\lib\net35\KellermanSoftware.Compare-NET-Objects.dll</HintPath>
<Reference Include="Common.Logging, Version=3.3.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<HintPath>..\packages\Common.Logging.3.3.1\lib\net40\Common.Logging.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="log4net, Version=1.2.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.4\lib\net45-full\log4net.dll</HintPath>
<Reference Include="Common.Logging.Core, Version=3.3.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<HintPath>..\packages\Common.Logging.Core.3.3.1\lib\net40\Common.Logging.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Common.Logging.Log4Net1213, Version=3.3.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<HintPath>..\packages\Common.Logging.Log4Net1213.3.3.1\lib\net40\Common.Logging.Log4Net1213.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -56,12 +64,10 @@
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.log4net.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\SolutionItems\App.config">
<Link>App.config</Link>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
Expand Down
5 changes: 2 additions & 3 deletions Difi.Oppslagstjeneste.Klient.Testklient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Common.Logging;
using Difi.Oppslagstjeneste.Klient.Domene.Entiteter.Enums;
using log4net;

namespace Difi.Oppslagstjeneste.Klient.Testklient
{
Expand All @@ -15,8 +15,7 @@ internal class Program
private static void Main(string[] args)
{
var avsendersertifikatThumbprint = CertificateIssuedToPostenNorgeAsIssuedByBuypassClass3Test4Ca3();
var konfigurasjon = new OppslagstjenesteKonfigurasjon(Miljø.FunksjoneltTestmiljøVerifikasjon2, avsendersertifikatThumbprint);

var konfigurasjon = new OppslagstjenesteKonfigurasjon(Miljø.FunksjoneltTestmiljøVerifikasjon2, avsendersertifikatThumbprint) {LoggForespørselOgRespons = false};
Log.Debug("> Starter program!");

//konfigurasjon.SendPåVegneAv = "984661185";
Expand Down

This file was deleted.

6 changes: 4 additions & 2 deletions Difi.Oppslagstjeneste.Klient.Testklient/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CompareObjects" version="1.0.2" targetFramework="net45" />
<package id="log4net" version="2.0.4" targetFramework="net45" />
<package id="Common.Logging" version="3.3.1" targetFramework="net45" />
<package id="Common.Logging.Core" version="3.3.1" targetFramework="net45" />
<package id="Common.Logging.Log4Net1213" version="3.3.1" targetFramework="net45" />
<package id="log4net" version="2.0.3" targetFramework="net45" />
</packages>
12 changes: 8 additions & 4 deletions Difi.Oppslagstjeneste.Klient/Difi.Oppslagstjeneste.Klient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@
<HintPath>..\packages\api-client-shared.1.0.5941.27271\lib\net45\ApiClientShared.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Difi.Felles.Utility, Version=0.5.5970.18522, Culture=neutral, PublicKeyToken=683b8efceae684a6, processorArchitecture=MSIL">
<HintPath>..\packages\difi-felles-utility-dotnet.0.5.5970.18522\lib\net45\Difi.Felles.Utility.dll</HintPath>
<Reference Include="Common.Logging, Version=3.3.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<HintPath>..\packages\Common.Logging.3.3.1\lib\net40\Common.Logging.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Common.Logging.Core, Version=3.3.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<HintPath>..\packages\Common.Logging.Core.3.3.1\lib\net40\Common.Logging.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="log4net, Version=1.2.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.4\lib\net45-full\log4net.dll</HintPath>
<Reference Include="Difi.Felles.Utility, Version=0.5.5970.18522, Culture=neutral, PublicKeyToken=683b8efceae684a6, processorArchitecture=MSIL">
<HintPath>..\packages\difi-felles-utility-dotnet.0.5.5970.18522\lib\net45\Difi.Felles.Utility.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
7 changes: 4 additions & 3 deletions Difi.Oppslagstjeneste.Klient/OppslagstjenesteHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Common.Logging;
using Difi.Oppslagstjeneste.Klient.Domene.Exceptions;
using Difi.Oppslagstjeneste.Klient.Envelope;
using Difi.Oppslagstjeneste.Klient.Handlers;
using Difi.Oppslagstjeneste.Klient.Svar;
using Difi.Oppslagstjeneste.Klient.Utilities;
using Difi.Oppslagstjeneste.Klient.XmlValidation;
using log4net;


namespace Difi.Oppslagstjeneste.Klient
{
Expand Down Expand Up @@ -73,8 +74,8 @@ private static void CheckResponseForErrors(Stream soapResponse)
{
var reader = new StreamReader(soapResponse);
var text = XmlUtility.ToXmlDocument(reader.ReadToEnd());
var exception = new SoapException(text);
Log.Error($"Uventet feil: {exception}");
var exception = new UventetFeilException(text);
Log.Warn($"Uventet feil: {exception}");
throw exception;
}

Expand Down
Loading

0 comments on commit c707ca6

Please sign in to comment.