question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Logged with log4net but log lines never appear in stackdriver.

See original GitHub issue

Like this user report on stack overflow, https://stackoverflow.com/questions/48962850/cant-write-log-entry-with-google-clouds-log4net-integration I followed the instructions here: https://googlecloudplatform.github.io/google-cloud-dotnet/docs/Google.Cloud.Logging.Log4Net/index.html Wrote this code: https://github.com/SurferJeffAtGoogle/csharp-docs-samples/tree/log4net/logging/api/Log4NetSample And ran it:

~/gitrepos/dotnet-docs-samples/logging/api/Log4NetSample$ dotnet run
log4net: log4net assembly [log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a]. (.NET Framework [.NET Core 4.6.0.0] on Linux 4.9.0-5-amd64 #1 SMP Debian 4.9.65-3+deb9u2 (2018-01-04))
log4net: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository for assembly [Log4NetSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]
log4net: Assembly [Log4NetSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [Not supported on .NETCore]
log4net: Assembly [Log4NetSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: Assembly [Log4NetSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy]
log4net: configuring repository [log4net-default-repository] using file [log4net.xml]
log4net: configuring repository [log4net-default-repository] using stream
log4net: loading XML configuration
log4net: Configuring Repository [log4net-default-repository]
log4net: Configuration update mode [Merge].
log4net: Logger [root] Level string is [ALL].
log4net: Logger [root] level set to [name="ALL",value=-2147483648].
log4net: Loading Appender [CloudLogger] type: [Google.Cloud.Logging.Log4Net.GoogleStackdriverAppender,Google.Cloud.Logging.Log4Net]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%-4timestamp [%thread] %-5level %logger %ndc - %message]
log4net: Converter [timestamp] Option [] Format [min=4,max=2147483647,leftAlign=True]
log4net: Converter [literal] Option [ [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [thread] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [] ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [level] Option [] Format [min=5,max=2147483647,leftAlign=True]
log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [logger] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [ndc] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: Setting Property [ProjectId] to String value [surferjeff-test2]
log4net: Setting Property [LogId] to String value [console]
log4net: Created Appender [CloudLogger]
log4net: Adding appender named [CloudLogger] to logger [root].
log4net: Hierarchy Threshold []
Hello World!

But nothing appears in my stackdriver logs: image

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
jskeetcommented, Apr 24, 2018

Reopened - Chris, are you okay to have a look at this?

1reaction
chrisdunelmcommented, Mar 1, 2018

OK, so this is broken in two ways:

  1. The LogManager.Flush call does absolutely nothing in .NETStandard projects; and this sample is .NETStandard, so it cannot work.
  2. On full .NET framework code, LogManager.Flush() requires the appender to implement IFlushable, which GoogleStackdriverAppender does not.

I will add IFlushable support in a PR soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

asp.net - Logs are not being sent to stackdriver using ...
I'm trying to use the Google.cloud.logging.log4net library in a .NET Web application to send logs to Google Stackdriver.
Read more >
Google.Cloud.Logging.Log4Net
Log4Net is a .NET client library to integrate Google Cloud Logging with log4net. Note: This documentation is for version 4.0.0 of the library....
Read more >
C# and .NET (log4net)
log4net is “a tool to help the programmer output log statements to a variety of output targets. log4net is a port of the...
Read more >
Google Cloud Platform Logging with a Practical Example
In this article, we will cover the basics of logging on Google Cloud Platform, including setting up log collection, sending logs to ...
Read more >
Log4net Tutorial for .NET Logging: 14 Best Practices and ...
Picking the right logging framework is hard, so that's why we're doing the work for you. Read this post to learn all you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found