博文

目前显示的是标签为“Assembly”的博文

Assembly in C#

1. using System.Reflection.Assembly System.Reflection.AssemblyName name = System.Reflection.Assembly.GetExecutingAssembly().GetName(); //name is {AssemblyNameInProperties, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null} byte[]  key =  name.GetPublicKey(); 2. reflection Assembly assem = typeof (ExampleClass).Assembly; // Create an object from the assembly, passing in the correct number // and type of arguments for the constructor. Object o = assem.CreateInstance( "Example" , false , BindingFlags.ExactBinding, null , new Object[] { 2 }, null , null ); // Make a late-bound call to an instance method of the object. MethodInfo m = assem.GetType( "Example" ).GetMethod( "SampleMethod" ); Object ret = m.Invoke(o, new Object[] { 42 }); Console.WriteLine( "SampleMethod returned {0}." , ret); reference: docs.microsoft.com/en-us/dotnet/api/system.re...

log4net in .Net Core

图片
Reference in .csproj  <ItemGroup>    <PackageReference Include="log4net" Version="2.0.8" />  </ItemGroup> log4net.Config. Assembly entryAssembly = Assembly.GetEntryAssembly() ; var logRepository = LogManager.GetRepository (entryAssembly); System.IO.FileInfo config = new System.IO.FileInfo(pathConfigFile); log4net.Config.XmlConfigurator.Configure( logRepository , config); https://msdn.microsoft.com/en-us/library/system.reflection.assembly(v=vs.110).aspx log4net.LogManager.GetLogger()            log4net.LogManager.GetLogger(typeof(T)); log4net. ILog log = log4net. LogManager .GetLogger( "testApp.Logging" ); log.Info( DateTime .Now.ToString() + ": login success" ); private log4net.ILog GetAppLogger<T>(T t) {    return log4net.LogManager.GetLogger(typeof(T)); } Content of configfile <?xml version="1.0" encoding="utf-8"...