Jump to content

Google Cloud Logging (Log4Net)


Recommended Posts

Hi there,

I'm wondering if its possible to use Google Cloud Logging with log4net? 

Based on this I setup my loader.log.conf like this:

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%message%newline" />
    </layout>
  </appender>
  <appender name="FileAppender" type="log4net.Appender.FileAppender">
    <file value="loader.log.txt" />
    <appendToFile value="true" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%message%newline" />
    </layout>
  </appender>
  <appender name="CloudLogger" type="Google.Cloud.Logging.Log4Net.GoogleStackdriverAppender,Google.Cloud.Logging.Log4Net">
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%-4timestamp [%thread] %-5level %logger %ndc - %message" />
    </layout>
    <logId value="plastiscm" />
  </appender>
  <root>
    <level value="INFO"/>
    <appender-ref ref="ConsoleAppender" />
    <appender-ref ref="FileAppender" />
    <appender-ref ref="CloudLogger" />
  </root>
</log4net>

But I see the following error:

log4net:ERROR Could not create Appender [CloudLogger] of type [Google.Cloud.Logging.Log4Net.GoogleStackdriverAppender,Google.Cloud.Logging.Log4Net]. Reported error follows.
System.TypeLoadException
  at (wrapper managed-to-native) System.Type:internal_from_name (string,bool,bool)
  at System.Type.GetType (System.String typeName, System.Boolean throwOnError, System.Boolean ignoreCase) [0x00011] in <8f2c484307284b51944a1a13a14c0266>:0
  at log4net.Util.SystemInfo.GetTypeFromString (System.Reflection.Assembly relativeAssembly, System.String typeName, System.Boolean throwOnError, System.Boolean ignoreCase) [0x00165] in <e1a77b5dfa0c4a1f8ba616
c017f5e0b8>:0
  at log4net.Util.SystemInfo.GetTypeFromString (System.String typeName, System.Boolean throwOnError, System.Boolean ignoreCase) [0x00006] in <e1a77b5dfa0c4a1f8ba616c017f5e0b8>:0
  at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender (System.Xml.XmlElement appenderElement) [0x00059] in <e1a77b5dfa0c4a1f8ba616c017f5e0b8>:0
log4net:ERROR Appender named [CloudLogger] not found.

This looked like it couldn't find the libraries. I tried copying in the following DLLs to the server directory in the hopes that it might pick up them up but I'm not sure if they need to be referenced at build time:

Google.Api.Gax.Grpc.GrpcCore.dll
Google.Api.Gax.Grpc.dll
Google.Api.Gax.dll
Google.Apis.Auth.dll
Google.Apis.Core.dll
Google.Apis.dll
Google.Cloud.DevTools.Common.dll
Google.Cloud.Logging.Log4Net.dll
Google.Cloud.Logging.Type.dll
Google.Cloud.Logging.V2.dll
Google.LongRunning.dll
Google.Protobuf.dll

Thanks,

Alex

Link to comment
Share on other sites

You can try the same with our .net core server build (check the download page). It uses the most modern .NET Core, and probably version issues are gone. (you'll need .net core compatible libraries though)

 

I'm very interested on this, we could write a blogpost and share with others :)

Link to comment
Share on other sites

Hey,

I forgot to make clear that I'm deploying this on Ubuntu 18.04.4 LTS, I'll try the server core version. I was using the standard version and copying the DLLs from Windows which seemed pretty flaky to begin with.

The following will install the dotnet core and the required libraries:

apt update
apt install -y wget
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb

add-apt-repository universe
apt update
apt install -y apt-transport-https
apt update
apt install -y dotnet-sdk-3.1

dotnet new console --output GoogleCloudLogging
dotnet add GoogleCloudLogging package Google.Cloud.Logging.Log4Net --version 3.1.0

The packages end up in ~/.nuget/packages and don't match Windows conventions (lower case and no suffix), do you think they would be picked up automatically from that directory or will I need to copy them to the server directory?

Do you happen to know the log4net version I should match?

 

I'll try some things out now. 

 

Link to comment
Share on other sites

You don't need the SDK. Just download our .NET Core build from our site. In case of Linux, we even have a proper package. Check the instructions.

 

Once you get it installed, I think copying the DLLs will be enough. You don't need to do dotnet new and all this stuff :)

Link to comment
Share on other sites

3 hours ago, psantosl said:

You don't need the SDK. Just download our .NET Core build from our site. In case of Linux, we even have a proper package. Check the instructions.

 

Once you get it installed, I think copying the DLLs will be enough. You don't need to do dotnet new and all this stuff :)

I'm deploying on Kubernetes with Helm so looking for something repeatable through code that will pull down the latest Plastic and latest Google Cloud Logging libraries.

5 hours ago, acutealex said:

Hey,

I forgot to make clear that I'm deploying this on Ubuntu 18.04.4 LTS, I'll try the server core version.

Sorry I've confused things, I meant to say I have been using server core and will try net core instead.

However I am not able to install it using the ubuntu:18.04 image (These are pretty much the commands from install documentation minus some sudo as it is not installed and this is running as root).

The following works:

apt-get update ; \
apt-get install -y apt-transport-https wget gnupg ; \
echo "deb https://www.plasticscm.com/plasticrepo/stable/ubuntu/ ./" | tee /etc/apt/sources.list.d/plasticscm-stable.list ; \
wget https://www.plasticscm.com/plasticrepo/stable/ubuntu/Release.key -O - | apt-key add - ; \
apt-get update ; \
apt-get install -y plasticscm-complete

But the following does not:

apt-get update ; \
apt-get install -y apt-transport-https wget gnupg ; \
echo "deb https://www.plasticscm.com/plasticrepo/stable/ubuntu/ ./" | tee /etc/apt/sources.list.d/plasticscm-stable.list ; \
wget https://www.plasticscm.com/plasticrepo/stable/ubuntu/Release.key -O - | apt-key add - ; \
apt-get update ; \
apt-get install -y plasticscm-server-netcore

The relevant part of the log for the error is: (should I report this rather than just posting this here? Edit: I reported it.)

debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x
86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.
pm line 7.)
debconf: falling back to frontend: Teletype
Setting up python3 (3.6.7-1~18.04) ...
running python rtupdate hooks for python3.6...
running python post-rtupdate hooks for python3.6...
Setting up python3-gi (3.26.1-2ubuntu1) ...
Setting up libgssapi-krb5-2:amd64 (1.16-2ubuntu0.1) ...
Setting up plasticscm-server-netcore (9.0.16.4146) ...
System has not been booted with systemd as init system (PID 1). Can't operate.
dpkg: error processing package plasticscm-server-netcore (--configure):
 installed plasticscm-server-netcore package post-installation script subprocess returned error exit status 1
Setting up python3-dbus (1.2.6-1) ...
Setting up networkd-dispatcher (1.7-0ubuntu3.3) ...
Created symlink /etc/systemd/system/multi-user.target.wants/networkd-dispatcher.service → /lib/systemd/system/networkd-dispatcher.service.
Processing triggers for systemd (237-3ubuntu10.39) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Errors were encountered while processing:
 plasticscm-server-netcore
5 hours ago, acutealex said:

The packages end up in ~/.nuget/packages and don't match Windows conventions (lower case and no suffix)

Sorry again, me being an idiot on a Friday, this is also wrong as those lower case names were actually directories that contain the DLLs. 

 

I think that if I can get the netcore version to install I can use the something like the following to download and copy the dependencies:

apt update ; \
apt install -y wget ; \
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb ; \
dpkg -i packages-microsoft-prod.deb ; \
add-apt-repository universe ; \
apt update ; \
apt install -y apt-transport-https ; \
apt update ; \
apt install -y dotnet-sdk-3.1 ; \
cd ~ ; \
dotnet new console --output GoogleCloudLogging ; \
dotnet add GoogleCloudLogging package Google.Cloud.Logging.Log4Net --version 3.1.0 ; \
dotnet publish GoogleCloudLogging --no-build -o pub ; \
cp -R GoogleCloudLogging/pub/* /opt/plasticscm/server
wget -q https://gist.githubusercontent.com/alexgeek/18f7ff1cab07b7d70e38ecf72d088d1b/raw/e25855ab17f05d64a6bb7663ee3855cbf64c885f/gistfile1.txt -O /opt/loader.log.conf

Are you using version 3.1.0 of log4net yet?

 

Thanks,

Alex

Link to comment
Share on other sites

9 hours ago, psantosl said:

Hi,

 

I think you're still trying to install plasticscm-complete and not plasticscm-server-netcore.

 

If you want to install without packages, then you can download Server .NET Core bundle from https://www.plasticscm.com/download/9.0.16.4146/linux

No I'm trying to install server net core but it is failing in my container due to a systemd issue. 

apt-get update ; \
apt-get install -y apt-transport-https wget gnupg ; \
echo "deb https://www.plasticscm.com/plasticrepo/stable/ubuntu/ ./" | tee /etc/apt/sources.list.d/plasticscm-stable.list ; \
wget https://www.plasticscm.com/plasticrepo/stable/ubuntu/Release.key -O - | apt-key add - ; \
apt-get update ; \
apt-get install -y plasticscm-server-netcore

results in:

System has not been booted with systemd as init system (PID 1). Can't operate.
dpkg: error processing package plasticscm-server-netcore (--configure):
 installed plasticscm-server-netcore package post-installation script subprocess returned error exit status 1
Setting up python3-dbus (1.2.6-1) ...
Setting up networkd-dispatcher (1.7-0ubuntu3.3) ...
Created symlink /etc/systemd/system/multi-user.target.wants/networkd-dispatcher.service → /lib/systemd/system/networkd-dispatcher.service.
Processing triggers for systemd (237-3ubuntu10.39) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Errors were encountered while processing:
 plasticscm-server-netcore
E: Sub-process /usr/bin/dpkg returned an error code (1)

 

The server does actually install however and can be run manually after that error. 

It looks like server net core uses version 2.0.8.0 for log4net, the closest version on nuget was 2.0.0 so I tried:

dotnet new console --output GoogleCloudLogging ; \
dotnet add GoogleCloudLogging package Google.Cloud.Logging.Log4Net --version 2.0.0 ; \
dotnet publish GoogleCloudLogging --no-build -o pub ; \
cp pub/*.dll /opt/plasticscm5/server/


I am getting some errors at startup e.g.:

log4net:ERROR Could not create Appender [CloudLogger] of type [Google.Cloud.Logging.Log4Net.GoogleStackdriverAppender,Google.Cloud.Logging.Log4Net]. Reported error follows.
System.IO.FileNotFoundException: Could not load file or assembly 'Google.Cloud.Logging.Log4Net, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

File name: 'Google.Cloud.Logging.Log4Net, Culture=neutral, PublicKeyToken=null'
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMarkHandle stackMark, ObjectHandleOnStack assemblyLoadContext, Boolean loadTypeFromPartialName, Obj
ectHandleOnStack type, ObjectHandleOnStack keepalive)
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, Boolean loadTypeFromPartialName)
   at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
   at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
   at log4net.Util.SystemInfo.GetTypeFromString(Assembly relativeAssembly, String typeName, Boolean throwOnError, Boolean ignoreCase)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
Application startup exception: System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The located assembly's manifes
t definition does not match the assembly reference. (0x80131040)
File name: 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.WebHost.BuildApplication()

 

Application startup exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The sy
stem cannot find the file specified.

File name: 'Microsoft.Extensions.DependencyModel, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.CSharpCompiler.EnsureOptions()
   at Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.CSharpCompiler.get_ParseOptions()
   at Microsoft.Extensions.DependencyInjection.RazorRuntimeCompilationMvcCoreBuilderExtensions.<>c__DisplayClass2_0.<AddServices>b__2(RazorProjectEngineBuilder builder)
   at Microsoft.AspNetCore.Razor.Language.RazorProjectEngine.Create(RazorConfiguration configuration, RazorProjectFileSystem fileSystem, Action`1 configure)
   at Microsoft.Extensions.DependencyInjection.RazorRuntimeCompilationMvcCoreBuilderExtensions.<>c.<AddServices>b__2_1(IServiceProvider s)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, Runti
meResolverLock lockType)
     
...

 

Link to comment
Share on other sites

Sadly no:

 

LD_LIBRARY_PATH=/root/pub /opt/plasticscm5/server/plasticd -console
log4net:ERROR Could not create Appender [CloudLogger] of type [Google.Cloud.Logging.Log4Net.GoogleStackdriverAppender,Google.Cloud.Logging.Log4Net]. Reported error follows.
System.IO.FileNotFoundException: Could not load file or assembly 'Google.Cloud.Logging.Log4Net, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

File name: 'Google.Cloud.Logging.Log4Net, Culture=neutral, PublicKeyToken=null'
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMarkHandle stackMark, ObjectHandleOnStack assemblyLoadContext, Boolean loadTypeFromPartialName, Obj
ectHandleOnStack type, ObjectHandleOnStack keepalive)
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, Boolean loadTypeFromPartialName)
   at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
   at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
   at log4net.Util.SystemInfo.GetTypeFromString(Assembly relativeAssembly, String typeName, Boolean throwOnError, Boolean ignoreCase)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)


log4net:ERROR Appender named [CloudLogger] not found.

 

Strange that it doesn't even seem to find the DLLs given that they are there:

ll pub/
total 2876
drwxr-xr-x 3 root root   4096 Apr 23 16:02 ./
drwx------ 1 root root   4096 Apr 23 16:03 ../
-rwxr--r-- 1 root root 293376 Mar 16 10:12 Google.Api.CommonProtos.dll*
-rwxr--r-- 1 root root   8192 Mar 16 10:12 Google.Api.Gax.Grpc.GrpcCore.dll*
-rwxr--r-- 1 root root  70656 Mar 16 10:12 Google.Api.Gax.Grpc.dll*
-rwxr--r-- 1 root root  77312 Mar 16 10:12 Google.Api.Gax.dll*
-rwxr--r-- 1 root root   5120 Mar  6 14:35 Google.Apis.Auth.PlatformServices.dll*
-rwxr--r-- 1 root root 118784 Mar  6 14:35 Google.Apis.Auth.dll*
-rwxr--r-- 1 root root  72704 Mar  6 14:35 Google.Apis.Core.dll*
-rwxr--r-- 1 root root  77312 Mar  6 14:35 Google.Apis.dll*
-rwxr--r-- 1 root root  33792 Mar 17 22:13 Google.Cloud.DevTools.Common.dll*
-rwxr--r-- 1 root root  34816 Apr 16 10:03 Google.Cloud.Logging.Log4Net.dll*
-rwxr--r-- 1 root root  17408 Mar 18 09:44 Google.Cloud.Logging.Type.dll*
-rwxr--r-- 1 root root 266240 Mar 18 10:13 Google.Cloud.Logging.V2.dll*
-rwxr--r-- 1 root root 363504 Feb 16 13:04 Google.Protobuf.dll*
-rwxr--r-- 1 root root  15344 Feb  4 22:39 Grpc.Auth.dll*
-rwxr--r-- 1 root root  50672 Feb  4 22:39 Grpc.Core.Api.dll*
-rwxr--r-- 1 root root 471024 Feb  4 22:39 Grpc.Core.dll*
-rwxr--r-- 1 root root  14712 Sep 13  2019 Microsoft.Bcl.AsyncInterfaces.dll*
-rwxr--r-- 1 root root 693680 Nov  9 00:56 Newtonsoft.Json.dll*
-rwxr--r-- 1 root root 221184 Mar  8  2017 log4net.dll*
drwxr-xr-x 5 root root   4096 Apr 23 16:02 runtimes/

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...