Try our conversational search powered by Generative AI!

Steve Celius
Mar 31, 2010
  12707
(0 votes)

log4net tips: Shortening the type name

If you’re using an appender layout like this:

   1: <layout type="log4net.Layout.PatternLayout">
   2:     <conversionPattern value="%date %level [%thread] %type.%method - %message%n" />
   3: </layout>

The conversion pattern is:

%date %level [%thread] %type.%method - %message%n

Which is the default one for the fileLogAppender shipping with EPiServer (note that type & method logging is slow, but immensely useful when you need it.)

A log line could look like this:

2009-12-09 17:27:04,655 INFO [6] Microsoft.Samples.Runtime.Remoting.Channels.Pipe.PipeConnection.Write - 18.3.1 Scheduler info:  2780> Write string Content-Type

The whole type name is included. In most cases, you just need the name of the class and method, which will save you some logging space (more on that later), but it will also make your log easier to read.

The %type pattern supports this syntax: %type{n} where <n> is the number of class/namespaces to include (from the right).

Changing the pattern to:

%date %level [%thread] %type{1}.%method - %message%n

yields the following log:
2009-12-09 17:27:04,655 INFO [6] PipeConnection.Write - 18.3.1 Scheduler info:  2780> Write string Content-Type

Read more about this in the log4net SDK documentation on the PatternLayout class.

Mar 31, 2010

Comments

Please login to comment.
Latest blogs
The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024

What's new in Language Manager 5.3.0

In Language Manager (LM) version 5.2.0, we added an option in appsettings.json called TranslateOrCopyContentAreaChildrenBlockForTypes . It does...

Quoc Anh Nguyen | Apr 15, 2024

Optimizely Search & Navigation: Boosting in Unified Search

In the Optimizely Search & Navigation admin view, administrators can set a certain weight of different properties (title, content, summary, or...

Tung Tran | Apr 15, 2024