Is it possible to configure log4net to roll files each hour? If not - any hints on how to override RollingFileAppender with required functionality to make HourlyRollingFileAppender?
Yes: set the datePattern element's value to "yyyyMMdd-HH"
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logfile" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd-HH" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
Ref: log4net Config Examples.
Related
I'm moving a project (and database) from Windows and SQL Server and Visual Studio, over to Linux Mint, MySQL and MonoDevelop. I'm most of the way done--but I can't get the type provider for MySQL to work. The most obvious sticking point seems to be that:
open FSharp.Data.Sql
Gives Error, the namespace of 'Sql' is not defined. (And I don't see a NuGet package for that name.)
There's no error on any of:
open MySql.Data
open MySqlConnector
open FSharp.Data
I seem to have packages/references to:
MySqlConnector
MySql.Data
FSharp.Data
FSharp.Data.SqlClient
FSharp.Data.TypeProviders
And then I also get an error for:
SqlDataProvider
"The type 'SqlDataProvider' is not defined'".
I'm sure this is very simple, but I'm not great at which or how to use references--sorry and thanks.
(And I don't really understand how to distinguish SQLProvider from FSharp.Data.Sql provider from MySql.Data.dll from MySqlConnector.dll...)
Edits: Thanks for questions. I assume this is .Net Framework, not Core. The project originated in defaults Visual Studio templates about 3 years ago, and I've never done anything to purse Core.
For the fsproj file(s)--I'm not sure what's what. I have 4 projects in the solution (only 2 actively being used). For the project with the type provider types, this is the project.fsproj.FileListAbsolute.txt, in /obj/Debug.
C:/Users/gen/Desktop/Simulations/SqlFunctions/bin/Debug/Library3.XML
C:/Users/gen/Desktop/Simulations/SqlFunctions/bin/Debug/Library3.exe
C:/Users/gen/Desktop/Simulations/SqlFunctions/bin/Debug/Library3.pdb
C:/Users/gen/Desktop/Simulations/SqlFunctions/bin/Debug/FSharp.Core.dll
C:/Users/gen/Desktop/Simulations/SqlFunctions/bin/Debug/FSharp.Data.TypeProviders.dll
C:/Users/gen/Desktop/Simulations/SqlFunctions/bin/Debug/FSharp.Core.xml
C:/Users/gen/Desktop/Simulations/SqlFunctions/bin/Debug/FSharp.Data.TypeProviders.xml
C:/Users/gen/Desktop/Simulations/SqlFunctions/obj/Debug/Library3.exe
C:/Users/gen/Desktop/Simulations/SqlFunctions/obj/Debug/Library3.pdb
/home/gen/Downloads/Simulations 2018-07-29/SqlFunctions/bin/Debug/Library3.XML
/home/gen/Downloads/Simulations 2018-07-29/SqlFunctions/obj/Debug/SqlFunctions.fsprojResolveAssemblyReference.cache
/home/gen/Downloads/Simulations 2018-07-29/SqlFunctions/obj/Debug/Library3.exe
/home/gen/Downloads/Simulations 2018-07-29/SqlFunctions/obj/Debug/Library3.pdb
The top half of those look like old Windows references-? Obviously none of it includes anything like MySql.Data--which does appear in project/References/From Packages.
Oh wait, this at the solution level may be more relevant (I've never worked with .fsproj files):
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>397e58f9-3730-4c45-a36f-7c9f64d94f1d</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>Simulations</RootNamespace>
<AssemblyName>Simulations</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.4.0.0</TargetFSharpCoreVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Name>Simulations</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Debug\Simulations.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Release\Simulations.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '11.0'">
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</Otherwise>
</Choose>
<Import Project="$(FSharpTargetsPath)" />
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="1a.fs" />
<Compile Include="2a.fs" />
<Compile Include="2b.fs" />
<Compile Include="2c.fs" />
<Compile Include="2d.fs" />
<Compile Include="2e.fs" />
<Compile Include="2f.fs" />
<Compile Include="3a.fs" />
<Compile Include="3b.fs" />
<Compile Include="3c.fs" />
<Compile Include="3d.fs" />
<Compile Include="4a.fs" />
<Compile Include="4b.fs" />
<Compile Include="4c.fs" />
<Compile Include="5a.fs" />
<Compile Include="5b.fs" />
<Compile Include="5c.fs" />
<Compile Include="5d.fs" />
<Compile Include="5e.fs" />
<Compile Include="6a.fs" />
<Compile Include="6b.fs" />
<Compile Include="7a.fs" />
<None Include="Script.fsx" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Numerics" />
<Reference Include="FSharp.Core">
<HintPath>packages\FSharp.Core.4.5.2\lib\net45\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="FSharp.Data.TypeProviders">
<HintPath>packages\FSharp.Data.TypeProviders.5.0.0.6\lib\net40\FSharp.Data.TypeProviders.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple">
<HintPath>packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="SqlFunctions\SqlFunctions.fsproj">
<Name>SqlFunctions</Name>
<Project>{14eefa95-3b68-4348-a7de-db29bfb3567f}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Thanks again.
Edit 2: As I comment below--the situation has progressed (I think) to: Invalid attempt to read when Reader is closed--error on the type declaration.
I just configured Perf4j on an app which uses Logback for logging. When I tried to setup the AsyncCoalescingStatisticsAppender I nested the appender-ref element which links on the other FileAppender.
But no messages came in to the referenced Appender.
When I was trying to debug it I found that no downstream appenders was set at all!
Then I replaced appender-ref element with a full appender declaration and the downstream appender was set.
I replaced this code
<appender name="CoalescingStatistics"
class="org.perf4j.logback.AsyncCoalescingStatisticsAppender">
<param name="TimeSlice" value="10000"/>
<appender-ref ref="filer" />
</appender>
with this:
<appender name="CoalescingStatistics" class="org.perf4j.logback.AsyncCoalescingStatisticsAppender">
<param name="TimeSlice" value="10000" />
<appender name="filer" class="ch.qos.logback.core.FileAppender">
<file>${logs.location}/perfStats.log</file>
<append>true</append>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
</appender>
Does the logback.xml appender element support nested appender-ref elements?
How do I configure logback to change the time of day for it's automatic rolling? I can't find it in the manual... Here's my logback.xml snippet:
<appender name="data" class="ch.qos.logback.core.FileAppender">
<file>mylog.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>mylog.%d{yyyy-MM-dd}.log.gz</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
This is a known unsupported feature.
[JIRA] (LOGBACK-205): rotate at an absolute time every day
Perhaps if I get time I will submit a pull request.
Try to do like this, Hope it will work for you.
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOGDIR}/filename.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<FileNamePattern>${LOGDIR}/file.%d{yyyy-MM-dd}.%i.log.gz
</FileNamePattern>
<!-- keep 30 days' worth of history -->
<MaxHistory>30</MaxHistory>
<!-- or whenever the file size reaches 10MB -->
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%date [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</encoder>
The above code will compress your file on the day basis or If the log file size exceeds 10MB.
Note : I have added "%i" in filePattern, It will iterate your file name as file1,file2 etc.
here my struts configuration
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources"/>
<constant name="struts.locale" value="ms_MY" />
<constant name="struts.multipart.maxSize" value="200097152" />
this configuration for *.properties
but for *.vm i dont know how to configure it.
please help me.
Let me preface this question by saying I've exhausted Google, or at least what I've been trying to search for. "log4j threshold", "log4j threshold category", "log4j appender threshold category", etc. But I really don't understand the results I'm getting back from Google.
This is the full configuration I've been given. I can't figure out how to modify it to suit my needs.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- ===================================================================== -->
<!-- -->
<!-- Log4j Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id: jboss-log4j.xml 62403 2007-04-18 15:26:43Z dimitris#jboss.org $ -->
<!--
| For more configuration infromation and examples see the Jakarta Log4j
| owebsite: http://jakarta.apache.org/log4j
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<!-- ================================= -->
<!-- Preserve messages in a local file -->
<!-- ================================= -->
<appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Append" value="false"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- ============================== -->
<!-- Append messages to the console -->
<!-- ============================== -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Target" value="System.out"/>
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<category name="com.arjuna">
<priority value="FATAL"/>
</category>
<category name="com.sun.facelets">
<priority value="ERROR"/>
</category>
<category name="jacorb">
<priority value="FATAL"/>
</category>
<category name="javax.enterprise.resource">
<priority value="WARNING"/>
</category>
<category name="javax.enterprise.resource.webcontainer.jsf">
<priority value="WARNING"/>
</category>
<category name="org.apache">
<priority value="FATAL"/>
</category>
<category name="org.hibernate">
<priority value="FATAL"/>
</category>
<category name="org.jboss">
<priority value="INFO"/>
</category>
<category name="org.jboss.ejb3.EJB3Deployer">
<priority value="WARNING" />
</category>
<category name="org.jboss.ejb3.JmxKernelAbstraction">
<priority value="WARNING" />
</category>
<category name="org.jboss.management">
<priority value="FATAL"/>
</category>
<category name="org.jboss.serial">
<priority value="FATAL"/>
</category>
<category name="org.jboss.wsf.framework">
<priority value="FATAL"/>
</category>
<category name="org.jgroups">
<priority value="FATAL"/>
</category>
<category name="org.quartz">
<priority value="FATAL" />
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>
I don't understand how the appender's "threshold" level interacts with the categories. See, I only want com.foo.bar messages to show on the console. But it seems like I'm getting a lot more than that, for instance, org.jboss.wsf.framework is dumping out DEBUG messages, even though I have a category with a name that matches it and set to FATAL.
I'm certain I'm manipulating the correct config file, as jboss reports it's reloading the config after I change it. So how do I set the category/threshold levels right? What's the difference between the threshold and category?
Example output (snipped). Why does quartz show up on the console when I have it set to FATAL?
2009-06-22 00:58:37,666 INFO [org.quartz.plugins.history.LoggingJobHistoryPlugin] Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer execution complete at 00:58:37 06/22/2009 and reports: null
2009-06-22 01:08:37,669 DEBUG [org.quartz.simpl.SimpleJobFactory] Producing instance of Job 'JobInitializationPlugin.JobInitializationPlugin_jobInitializer', class=org.quartz.jobs.FileScanJob
2009-06-23 15:44:17,790 INFO [org.jboss.wsf.stack.jbws.NativeServerConfig] 3.0.5.GA
2009-06-23 15:44:17,868 DEBUG [org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl] setDeploymentAspects on WSDeploymentAspectManagerEJB
2009-06-23 15:44:17,868 DEBUG [org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl] setDeploymentAspects on WSDeploymentAspectManagerEndpointAPI
To answer the specific question of why does Quartz show up on the logging, you would have to change the Quartz configuration as follows:
<category name="org.quartz" additivity="false">
<priority value="FATAL" />
</category>
The additivity attribute tells log4j to override the root setting and use this only for org.quartz.
In a previous version of the question you stated you only wanted those messages from those classes turned on, to do that you have to start with configuring the priority in the root element to fatal (or even NO) and then it will only log those packages/classes that you turn on explicitly.
To answer your question about how threshold interacts with category, basically think of it is as a publish/subscribe. The category sets what is published by the logger, the threshold sets the subscription level of the appender.
This is complicated slightly be the fact that category is not a single thing, but rather a hierarchy, so the fact that you set the publishing level on one category isn't the whole story. It may be overridden in the hierarchy, as it was in your case.
Move "<appender-ref ref="CONSOLE"/>" from <root> to <category name="com.foo.bar">.
I.e.:
<category name="com.foo.bar">
<priority value="DEBUG"/>
<appender-ref ref="CONSOLE"/>
</category>
<root>
<appender-ref ref="FILE"/>
</root>
With the config that you show the console shouldn't get any debug messages so check if any other config could be used or if some code is programatically changing the config.