ctaggart / google-cloud-dotnet

Google Cloud Client Library for .NET
https://googlecloudplatform.github.io/google-cloud-dotnet/
Apache License 2.0
0 stars 0 forks source link

GoogleStackdriverAppender leads to System.AccessViolationException #1

Open ctaggart opened 7 years ago

ctaggart commented 7 years ago

image

Program.cs

using System;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        // debug log4net
        //log4net.Util.LogLog.InternalDebugging = true;

        // debug grpc
        //Environment.SetEnvironmentVariable("GRPC_TRACE", "all", EnvironmentVariableTarget.Process);
        //Environment.SetEnvironmentVariable("GRPC_VERBOSITY", "debug", EnvironmentVariableTarget.Process);
        //Grpc.Core.GrpcEnvironment.SetLogger(new Grpc.Core.Logging.ConsoleLogger());

        log4net.Config.XmlConfigurator.Configure(new FileInfo("log4net.xml"));
        var log = log4net.LogManager.GetLogger(typeof(Program));
        log.Info("An exciting log entry!");
        log.Info("Another exciting log entry!");

        Console.ReadKey();
    }
}

log4net.xml

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%-4timestamp [%thread] %-5level %logger %ndc - %message" />
    </layout>
  </appender>
  <appender name="CloudLogger" type="Google.Logging.Log4Net.GoogleStackdriverAppender,Google.Logging.Log4Net">
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%-4timestamp [%thread] %-5level %logger %ndc - %message" />
    </layout>
    <projectId value="tachyusatmion" />
    <logId value="myLog" />
    <!--<withMetaData value="Location" />-->
    <withMetaData value="ThreadName" />
  </appender>
  <root>
    <level value="DEBUG" />
    <appender-ref ref="ConsoleAppender" />
    <appender-ref ref="CloudLogger" />
  </root>
</log4net>

testlog4net.csproj

<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
    <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="**\*.cs" />
    <EmbeddedResource Include="**\*.resx" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="log4net.xml">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Google.Logging.Log4Net">
      <Version>1.0.0-beta04</Version>
    </PackageReference>
    <PackageReference Include="NETStandard.Library">
      <Version>1.6.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.NET.Sdk">
      <Version>1.0.0-alpha-20161104-2</Version>
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
    <PackageReference Include="System.Diagnostics.DiagnosticSource">
      <Version>4.3.0</Version>
    </PackageReference>
    <Reference Include="System" />
    <Reference Include="System.Interactive.Async">
      <HintPath>..\google-cloud-dotnet\apis\Google.Logging.V2\Google.Logging.Log4Net\bin\Release\net45\System.Interactive.Async.dll</HintPath>
    </Reference>
    <Reference Include="System.Runtime.InteropServices.RuntimeInformation">
      <HintPath>..\google-cloud-dotnet\apis\Google.Logging.V2\Google.Logging.Log4Net\bin\Release\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
    </Reference>
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup />
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
ctaggart commented 7 years ago

This code works fine without issue in Visual Studio 2015, so let's dig. I just noticed this:

image

Severity    Code    Description Project File    Line    Suppression State
Warning MSB3243 No way to resolve conflict between "System.Interactive.Async, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263" and "System.Interactive.Async, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263". Choosing "System.Interactive.Async, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263" arbitrarily.    testlog4net G:\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets   1909    

Severity    Code    Description Project File    Line    Suppression State
Warning MSB3243 No way to resolve conflict between "System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.  testlog4net G:\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets   1909    
ctaggart commented 7 years ago

That assembly redirect errors appear to be not needed. A testlog4net.exe.config is built automatically in the output directory and has both entries.