Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6566425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:12:55+00:00 2026-05-25T14:12:55+00:00

Is there a way to add the assembly version of assembly that is emiting

  • 0

Is there a way to add the assembly version of assembly that is emiting the logging event?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:12:56+00:00Added an answer on May 25, 2026 at 2:12 pm

    I don’t think there is anything built-in that will do this, so you will probably need to create your own custom PatternConverter and PatternLayout (which is very easy)

    The biggest problem is speed, since this will require log4net to generate the caller information and (in their own words)

    WARNING Generating the caller class information is slow. Thus, its use should be avoided unless execution speed is not an issue.

    If speed is not an issue, then something like this should work.

    public class AssemblyVersionPatternConverter : log4net.Util.PatternConverter
    {
        protected override void Convert(TextWriter writer, object state)
        {
            var le = state as log4net.Core.LoggingEvent;
            if (le != null) 
                writer.Write(GetAssemblyVersion(le.LocationInformation.ClassName));
        }
    }
    
    public class AssemblyVersionPatternLayout : log4net.Layout.PatternLayout
    {
        public AssemblyVersionPatternLayout()
        {
            AddConverter( new ConverterInfo 
              { 
                 Name = "AssemblyVersion", 
                 Type = typeof(AssemblyVersionPatternConverter) 
              });
        }
    }
    

    Apart from writing the GetAssemblyVersion method, that is all it takes to implement your own customer PatternConverter and PatternLayout.

    You then have to change your log4net configuration file to tell it to use your custom routines.

    eg if you have something like

    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%5level %message%newline" />
    </layout>
    

    you change it to something like

    <layout type="MyNameSpace.AssemblyVersionPatternLayout, MyDllname">
        <conversionPattern value="%5level %AssemblyVersion  %message%newline" />
    </layout>
    

    The GetAssemblyVersion method, could be something like the following

    private string GetAssemblyVersion(string className)
    {
        Type type = Type.GetType(className);
        System.Reflection.Assembly assembly ;
        if (type != null) 
           assembly = type.Assembly ;
        else
           assembly = AppDomain.CurrentDomain.GetAssemblies()
              .FirstOrDefault(a => a.GetType(className) != null);
    
        if (assembly == null)
            return String.Empty;
    
        return assembly.FullName.Split(',')[1].Replace("Version=", "");
     }
    

    Note, it is not recommended to use assembly.GetName().Version as this can throw a SecurityException if the account has very local privileges.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to add a text-shadow in CSS that is similar to
Is there a way to add assembly attributes to a Managed C++ assembly? In
I created this regular expression to validate names: ^[a-zA-Z0-9\s\-\,]+.\*?$ Is there a way add
Is there a way to add the ActiveMQ component via javacode in Spring's applicationConfig
Is there a way to add a daily total to a graph made with
Is there a way to add the select-result on the url when the pop
Is there a way to add a progress bar in the footer (fbar) of
Is there a way to add custom template inside Telerik MVC Combobox.? I have
Is there a way to add keyboard navigation to links with just css3, without
Is there a way to add images dynamically to a photoswipe gallery after it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.