Log4Net Levels Numeric Values - log4net

I can't seem to find the numeric values for the predefined levels in Log4Net. Can anybody point me to them?

The trunk code for Level.cs gives these numbers:
Off: int.MaxValue (2,147,483,647; 0x7FFFFFFF)
Emergency: 120000
Fatal: 110000
Alert: 100000
Critical: 90000
Severe: 80000
Error: 70000
Warn: 60000
Notice: 50000
Info: 40000
Debug: 30000
Fine: 30000
Trace: 20000
Finer: 20000
Verbose: 10000
Finest: 10000
All: int.MinValue (-2,147,483,648; 0x80000000)

Here is an excerpt from the Level class (decompiled with .net reflector)
public static readonly Level Alert = new Level(0x186a0, "ALERT");
public static readonly Level All = new Level(-2147483648, "ALL");
public static readonly Level Critical = new Level(0x15f90, "CRITICAL");
public static readonly Level Debug = new Level(0x7530, "DEBUG");
public static readonly Level Emergency = new Level(0x1d4c0, "EMERGENCY");
public static readonly Level Error = new Level(0x11170, "ERROR");
public static readonly Level Fatal = new Level(0x1adb0, "FATAL");
public static readonly Level Fine = new Level(0x7530, "FINE");
public static readonly Level Finer = new Level(0x4e20, "FINER");
public static readonly Level Finest = new Level(0x2710, "FINEST");
public static readonly Level Info = new Level(0x9c40, "INFO");
private readonly string m_levelDisplayName;
private readonly string m_levelName;
private readonly int m_levelValue;
public static readonly Level Notice = new Level(0xc350, "NOTICE");
public static readonly Level Off = new Level(0x7fffffff, "OFF");
public static readonly Level Severe = new Level(0x13880, "SEVERE");
public static readonly Level Trace = new Level(0x4e20, "TRACE");
public static readonly Level Verbose = new Level(0x2710, "VERBOSE");
public static readonly Level Warn = new Level(0xea60, "WARN");

Related

Convert List of Objects to List of Strings

I'm using Spring data jpa findAll() method. So it returns List of objects.
here is the entity.
#Entity
#Table(name = "country")
#Data
public class CountryEntity {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "country_id")
private Long id;
#Column(name = "country_name")
private String name;
#OneToMany(mappedBy ="countryEntity")
private Collection<GovernmentEntity> governments;
}
and data jpa findAll() method is
List<CountryEntity> entities = countryRepo.findAll();
I want to get list of Country names as String WITHOUT USING loops or streams (performance issues).
I used streams and it works fine with javaFx ListView
#FxmlView("/address.fxml")
#Component
#RequiredArgsConstructor
public class HomeController implements Initializable {
private ObservableList<String> countriesNames;
#FXML
private ListView<String> countryListView;
#Override
public void initialize(URL url, ResourceBundle resourceBundle) {
List<CountryEntity> entities = countryRepo.findAll();
List <String> countryList = entities.stream().map(o-> Objects.toString(o.getName())).collect(Collectors.toList());
countriesNames = FXCollections.observableList(countryList);
countryListView.getItems().addAll(countriesNames);
}
}
Make your ListView a ListView<CountryEntity>, and use a cell factory to customize the display:
public class HomeController implements Initializable {
private ObservableList<String> countriesNames;
#FXML
private ListView<CountryEntity> countryListView;
#Override
public void initialize(URL url, ResourceBundle resourceBundle) {
List<CountryEntity> entities = countryRepo.findAll();
countryListView.getItems().addAll(entities);
countryListView.setCellFactory(lv -> new ListCell<CountryEntity>() {
#Override
protected void updateItem(CountryEntity country, boolean empty) {
super.updateItem(country, empty);
if (empty || country == null) {
setText("");
} else {
setText(country.getName()); // or however you want to display it
}
});
}
}
If you genuinely only want a list of country names, and don't want to retrieve a list of CountryEntitys and extract the names from them, then you need to define a method in your repository for the purpose:
public interface CountryEntityRepository extends JpaRepository<CountryEntity, Long> {
// existing methods...
#Query("select c.name from CountryEntity c")
List<String> findCountryNames() ;
}
And then of course just do
#FXML
private ListView<String> countryListView ;
#Override
public void initialize(URL url, ResourceBundle resourceBundle) {
countryListView.getItems().addAll(countryRepo.findCountryNames());
}
However, the first approach is almost certainly preferred. You will likely need the other data in the CountryEntity at some point.

ASP.NET CORE 2.0 runtime value using DI

In ASP.NET CORE 2.0, how can I pass runtime parameter(string type) such as dynamic connection string to my service as Dependency injection. The string parameter value will be dynamic and be taken from HttpContext.
I'm not able to understand how can I pass runtime parameter value using DI from Controller->Service->Repository class?
Below code is what I'm using. Please guide me.
Code
public class AccountController : BaseController//Controller
{
ILogger<AccountController> _logger;
private IUserService _userService;
public AccountController(
ILogger<AccountController> logger
, IUserService userService
) {
_logger = logger;
_userService = userService;
}
public class UserService : IUserService
{
private readonly IUserRepository _userRepository;
private readonly IRoleRepository _roleRepository;
public UserService(
IUserRepository userRepository
,IRoleRepository roleRepository
)
{
_userRepository = userRepository;
_roleRepository = roleRepository;
}
public class UserRepository : DbProvider, IUserRepository
{
private IConfiguration _configuration;
private DatabaseSetting _databaseSetting;
public UserRepository(IConfiguration configuration, IOptions<DatabaseSetting> databaseSetting) : base(configuration, databaseSetting)
{
_configuration = configuration;
_databaseSetting = databaseSetting.Value;
}
public static class StartupExtensions
{
public static IServiceCollection AddCloudscribeCore(this IServiceCollection services, IConfiguration configuration)
{
// Add application repository.
services.AddSingleton<AuthAttributeFilter>();
#region Add Repository Dependency Here
services.AddTransient<IUserRepository, UserRepository>();
services.AddTransient<IRoleRepository, RoleRepository>();
#endregion Repository Dependency
#region Add Service Dependency Here
services.AddTransient<ICompanyService, CompanyService>();
services.AddTransient<IUserService, UserService>();
#endregion Service Dependency
services.Configure<DatabaseSetting>(options =>
{
options.DBProvider = configuration["DatabaseSetting:DBProvider"];
options.ConnectionString = configuration["DatabaseSetting:ConnectionString"];
});
return services;
}
}
For accessing HttpContext in Service and Repository, there is no need to pass from Controller, try IHttpContextAccessor.
public class UserRepository : DbProvider, IUserRepository
{
private IConfiguration _configuration;
private DatabaseSetting _databaseSetting;
private readonly IHttpContextAccessor _accessor;
public UserRepository(IConfiguration configuration, IOptions<DatabaseSetting> databaseSetting, IHttpContextAccessor accessor) : base(configuration, databaseSetting)
{
_configuration = configuration;
_databaseSetting = databaseSetting.Value;
_accessor = accessor;
}
Then, you could access HttpContext by _accessor.HttpContext.

word wrap for JTextArea not available not found in java

i am creating notepad and i have given the option of word wrap as in notepad
but when i write
textArea.setLineWrap(true);
than it gives me the error as shown
cannot Find Symbol
Symbol: method setLineWrap(boolean)
Location: Variable textArea of type TextArea
even when i press '.' and dropdown came for textArea but it doesnt shows setLineWrap boolean method
here is my code so far:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package test3;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
class Test3 extends JFrame{
private final JMenu Format;
private final JMenuItem Word;
private final TextArea textArea = new TextArea("", 0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
public Test3(){
setLayout(new FlowLayout()); //Default layout
JMenuBar menubar=new JMenuBar();
setJMenuBar(menubar);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(textArea);
Format=new JMenu("Format");
Word=new JMenuItem("Word wrap");
Format.add(Word);
menubar.add(Format);
event1 e1 =new event1 ();
Word.addActionListener(e1);
}
public class event1 implements ActionListener{
#Override
public void actionPerformed(ActionEvent e) {
//textArea.setLineWrap(true);
//textArea.setWrapStyleWord(true);
}
}
public static void main(String []args){
Test3 t=new Test3();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
t.setTitle("Notepad");
t.setVisible(true);
t.setSize(1280,786);
}
}
I Have changed your code little bit.
Instead of TextArea I have used JTextArea
and a JScrollPane to wrap the JTextArea
class Test3 extends JFrame {
private final JMenu Format;
private final JMenuItem Word;
private final JTextArea textArea = new JTextArea("", 0, 0);
public Test3() {
setLayout(new FlowLayout()); //Default layout
JScrollPane scroll = new JScrollPane (textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JMenuBar menubar = new JMenuBar();
setJMenuBar(menubar);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(scroll);
Format = new JMenu("Format");
Word = new JMenuItem("Word wrap");
Format.add(Word);
menubar.add(Format);
event1 e1 = new event1();
Word.addActionListener(e1);
}
public class event1 implements ActionListener {
#Override
public void actionPerformed(ActionEvent e) {
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
}
}
public static void main(String[] args) {
Test3 t = new Test3();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
t.setTitle("Notepad");
t.setVisible(true);
t.setSize(1280, 786);
}
}
Instead of using TextArea use JTextArea.
class test2{
private final JMenu Format;
private final JMenuItem Word;
private final JTextArea textArea = new JTextArea("", 0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
test2(){
setLayout (new FlowLayout()); //Default layout
JMenuBar menubar=new JMenuBar();
setJMenuBar(menubar);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(textArea);
format=new JMenu("Format");
Word=new JMenuItem("Word wrap");
format.add(Word);
menubar.add(format);
event1 e1 =new event1 ();
Word.addActionListener(e18);
}
public class event18 implements ActionListener{
#Override
public void actionPerformed(ActionEvent e) {
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
}
}
public static void main(String []args){
Test2 t=new Test2();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
t.setTitle("Notepad");
t.setVisible(true);
t.setSize(1280,786);
}
}

using JAXB, the XML is loaded into a class. This class is then used within another class to be marshalled out differently

Given an XML file of offerings that is then loaded into a class called Offerings via JAXB.
This class has the following:
Name, Price sub-Class, Modifiers, Ordering Rules etc.
I then create an order and within that order
Order
public class ProductOrder {
private String OrderId;
private Date createDate;
private OrderStatus orderStatus;
private int CustomerOrderID;
private ArrayList<ProductOrderItem> productOrderItems = new ArrayList<ProductOrderItem>();
}
Order Item
public class ProductOrderItem {
private int OrderItemID;
private **Offering** offering;
private Map<String, Integer> qtylist = new HashMap<String, Integer>();
private ArrayList<Modifier> modifiers = new ArrayList<Modifier>();
private int qty;
}
Offering
#XmlRootElement(name = "offering")
#XmlAccessorType(XmlAccessType.FIELD) // NONE)
public class Offering {
#XmlAttribute
private String id;
#XmlElement
private String offeringName;
#XmlElement
private String description;
#XmlElement
private Integer price;
}
The Offering and Modifiers are classes with JAXB already which I only want to push part of the XML. How would I change the anotations such that only part of the elements are sent? For example not the offering -> modifiers?
Use #XmlTransient instead of the #XmlElement tag.

Enum-Like object which contains properties

I am trying to figure out a way to have a class full of static objects which each can have a variety of static properties.
I want to be able to pass these properties around and even set them as static properties of other object and I also want to be able to switch through the objects.
Here is an example illustrating what I mean:
Creating and Sending a Message
class Program
{
static void Main(string[] args)
{
MarketOrder Order = new MarketOrder("DELL", MessageProperties.SecurityType.Equity, MessageProperties.ExchangeDestination.ARCA.PostOnly);
SendOrder(Order);
Console.ReadLine();
}
public static void SendOrder(MarketOrder Order)
{
switch (Order.SecurityType)
{
case MessageProperties.SecurityType.Equity:
// Equity sending logic here
break;
case MessageProperties.SecurityType.Option:
// Option sending logic here
break;
case MessageProperties.SecurityType.Future:
// Future sending logic here
break;
}
}
}
This does not want to compile because it won't let me switch the Order.SecurityType object.
MarketOrder Class
public class MarketOrder
{
public readonly string Symbol;
public readonly MessageProperties.SecurityType SecurityType;
public readonly MessageProperties.ExchangeDestination ExchangeDestination;
public MarketOrder(string Symbol, MessageProperties.SecurityType SecurityType, MessageProperties.ExchangeDestination ExchangeDestination)
{
this.Symbol = Symbol;
this.SecurityType = SecurityType;
this.ExchangeDestination = ExchangeDestination;
}
}
MessageProperties Class
public abstract class MessageProperties
{
public class ExchangeDestination
{
public readonly string Value;
public readonly double ExchangeFee;
public ExchangeDestination(string Value, double ExchangeFeed)
{
this.Value = Value;
this.ExchangeFee = ExchangeFee;
}
public abstract class ARCA
{
public static ExchangeDestination Only = new ExchangeDestination("ARCA.ONLY", 0.01);
public static ExchangeDestination PostOnly = new ExchangeDestination("ARCA.ONLYP", 0.02);
}
public abstract class NYSE
{
public static ExchangeDestination Only = new ExchangeDestination("NYSE.ONLY", 0.01);
public static ExchangeDestination PostOnly = new ExchangeDestination("NYSE.ONLYP", 0.03);
}
}
public class SecurityType
{
public readonly string Value;
public SecurityType(string Value)
{
this.Value = Value;
}
public static SecurityType Equity = new SecurityType("EQ");
public static SecurityType Option = new SecurityType("OPT");
public static SecurityType Future = new SecurityType("FUT");
}
}
Enums work perfectly for what I am trying to do except it is hard to have multiple properties of an enum value. I considered using Attributes on Enums to set the properties but getting those vs. getting static properties of objects is substantially slower and my application is extremely speed/latency sensitive.
Is there perhaps a better way of accomplishing what I am trying to do?
Thanks in advance for your help!
William

Resources