Log4j2 RollingFile appender start archiving after N days? - configuration

This is the conf I am using at the moment:
<RollingFile name="RollingFileAppender"
fileName="/tmp/test.log" filePattern="/tmp/test-%i.log.gz" ignoreExceptions="false">
<PatternLayout pattern="%m%n" />
<Policies>
<SizeBasedTriggeringPolicy size="100 MB" />
</Policies>
<DefaultRolloverStrategy max="5" />
</RollingFile>
Notice the '.gz' extension that make log4j2 compress the rotated log files.
I would like to keep 5 files uncompressed and start compressing only after that.
Is there a way to start the compression after N rotations?

Related

API Management - the same policy created for every operation

When I add an API using the Function App option. All the functions are imported as operations and every operation has the same backend policy:
<inbound>
<base />
<set-backend-service id="apim-generated-policy" backend-id="myfunctionapp" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
I have a lot of these operations and all of them have the same policy. There is a way to create a shared policy for all operations. So it would seem better to create one shared policy instead of policy for each operation.
Is there a way, during the "add API" step, to specify a shared policy for all operations and not have these policies on each operation? I couldn't find a way (at least not in Azure UI). Is there another way to do that?
If you want to apply the policy to all operations, select All operations.
Select the </> (code editor) icon in the Inbound processing section.
And then paste the desired policy code into one of the appropriate blocks.
<policies>
<inbound>
<base />
<set-backend-service id="apim-generated-policy" backend-id="myfunctionapp" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
For more details you could refer to this article.

How to configure mapcache to cache tile from a tms service

I have a mapserver with mapcache on a server.
I know how to configure mapcache to cache tile from a wms service.
But I can't find anywhere how to configure mapcache to cache tile from a TMS service (openstreetmap https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png)
On the mapcache page https://mapserver.org/mapcache/index.html it is said
"services WMS, WMTS, TMS, VirtualEarth/Bing and Google Maps requests: Supported Tile Services"
I see the line below on https://mapserver.org/mapcache/services.html#mapcache-services
"
To activate the TMS service, add these lines to the mapcache.xml configuration file:
<service type="tms" enabled="true"/>
"
but it's for a client to get tms tile from mapcache, not to mapcache to get the tile from a tms service
I Don't know if it is even possible, because I found no exemple.
To get from a WMS I had the above
<source name="name1" type="wms">
<getmap>
<params>
<LAYERS>layer1</LAYERS>
</params>
</getmap>
<http>
<url>http://an_rul.com/ows/name1</url>
</http>
</source>
<tileset name="name1">
<source>name1</source>
<cache>disk</cache>
<grid>GoogleMapsCompatible</grid>
<format>PNG</format>
<metatile>5 5</metatile>
<metabuffer>10</metabuffer>
<expires>3600</expires>
</tileset>
<service type="wms" enabled="true">
<full_wms>assemble</full_wms>
<resample_mode>bilinear</resample_mode>
<format>PNG</format>
<maxsize>4096</maxsize>
<forwarding_rule name="catch all">
<http>
<url>http://an_rul.com/ows/name1</url>
</http>
</forwarding_rule>
</service>
<service type="tms" enabled="true"/>
For a TMS i'd like to have this sort of thing
<source name="name1" type="tms"> <-- note the tms type i'd like
<getmap>
<params>
<LAYERS>layer1 ?</LAYERS> <-- what layer can I put there ?
</params>
</getmap>
<http>
<url>https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png ??</url> <-- which url should I write ??
</http>
</source>
<tileset name="name1">
<source>name1</source>
<cache>disk</cache>
<grid>GoogleMapsCompatible</grid>
<format>PNG</format>
<metatile>5 5</metatile>
<metabuffer>10</metabuffer>
<expires>3600</expires>
</tileset>
<service type="wms" enabled="true">
<full_wms>assemble</full_wms>
<resample_mode>bilinear</resample_mode>
<format>PNG</format>
<maxsize>4096</maxsize>
<forwarding_rule name="catch all">
<http>
<url>http://an_rul.com/ows/name1</url>
</http>
</forwarding_rule>
</service>
<service type="tms" enabled="true"/>
Thank You
MapCache does not support TMS as a source. See https://mapserver.org/mapcache/config.html
A source is a service mod-mapcache can query to obtain image data.
This is typically a WMS server accessible by a URL. (There are
currently only WMS, WMTS and mapfile as sources, though others may be
added later if the need arises, see Data Sources).
You can use MapProxy instead, it supports TMS sources (tiles) https://mapproxy.org/docs/nightly/sources.html

Is Limit call rate by subscription supported in Consumption tier?

I am trying to add a rate-limit policy for an API management (per API Management access restriction policies) and I am not sure if I do something wrong or if documentation is not correct.
According to the documentation, the
Set usage quota by key
Limit call rate by key
are not available in consumption tier, but Limit call rate by subscription has no such notice, so it should work (plus Set usage quota by subscription can be set).
I have an Azure API Management, I have created a sample API and a product and in the policy of the product is:
<policies>
<inbound>
<base />
<quota calls="100" renewal-period="86400" />
<rate-limit calls="20" renewal-period="90" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
When I click on Save, I get
One or more fields contain incorrect values:
Error in element 'rate-limit' on line 16, column 10: Policy is not allowed in this sku 'Consumption'
Is there a way to set the rate-limit (=am I missing something) for consumption tier or is the documentation not correct?
You can now use the rate-limit and quota tag in policies at API level.
<policies>
<inbound>
<base />
<rate-limit calls="5" renewal-period="60" remaining-calls-variable-name="remainingCallsPerSubscription" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
Using quotas:
<policies>
<inbound>
<base />
<quota calls="10000" renewal-period="3600" />
</inbound>
<outbound>
<base />
</outbound>
</policies>
Edit: on the consumption tier you can only apply these policies on API level. (So they apply to everyone that uses the API)
There is an ongoing update, once complete (a few days at most) "rate-limit" will be enabled for Consumption SKU, "rate-limit-by-key" disabled.

Azure API Management: Doing a global policy for set-backend-service results in scope error

So globally on my API service, I always wish to set the backend service URL based on certain calling regions.
According to this MSDN library article, using the set-backend-service policy sounds perfect for this, and it's a global policy according to its policy scope at the bottom.
However, even posting their exact example...
<policies>
<inbound>
<choose>
<when condition="#(context.Request.Url.Query.GetValueOrDefault("version") == "2013-05")">
<set-backend-service base-url="http://contoso.com/api/8.2/" />
</when>
<when condition="#(context.Request.Url.Query.GetValueOrDefault("version") == "2014-03")">
<set-backend-service base-url="http://contoso.com/api/9.1/" />
</when>
</choose>
</inbound>
....results in an error:
"Error in element 'set-backend-service' on line 0, column 0: Policy is
not allowed in the specified scope"
I can't figure out how to make it any simpler of a situation to troubleshoot. I even removed the conditional statement and just left the policy alone and it still shows the scope error.
I know this global scope works okay, since I was able to put in an xml-to-json policy as a temporary test and save successfully.
I would figure someone ran into this issue already, as this must be a common use case for this policy. Otherwise, I think the MSDN article is out of date, unless anyone here can see any issues.
Here's my policy scope for global:
Change the quotes to single quotes where "version" is. I just ran the following no problem:
<policies>
<inbound>
<choose>
<when condition="#(context.Request.Url.Query.GetValueOrDefault('version') == '2013-05')">
<set-backend-service base-url="http://contoso.com/api/8.2/" />
</when>
<when condition="#(context.Request.Url.Query.GetValueOrDefault('version') == '2014-03')">
<set-backend-service base-url="http://contoso.com/api/9.1/" />
</when>
</choose>
<base />
</inbound>
<outbound>
<base />
</outbound>
</policies>

NLog mySQL database as target configuration

I am using Nlog with MYsql as target database.
MY configuration is as below:
<target name="databaselog" type="Database" keepConnection="true"
useTransactions="false"
dbProvider="MySql.Data.MySqlClient"
connectionString="Server=localhost;Database=****;User ID=****;Password=****;Connect Timeout=5;"
commandText=" insert into logs(time_stamp,logger,message,log_level) Values(#TIME_STAMP,#LOGGER,#MESSAGE,#LOGLEVEL)">
<parameter name="#TIME_STAMP" layout="${longdate}"/>
<parameter name="#LOGGER" layout="${logger}"/>
<parameter name="#MESSAGE" layout="${message}"/>
<parameter name="#LOGLEVEL" layout="${level:uppercase=true}"/>
</target>
.
Still not able to insert the info or any level message in MYSql DB.
Can anyone please help me out ?
bye the I also tried command text as
insert into logs(time_stamp,logger,message,log_level) Values(?,?,?,?)
but not able to insert the data in mysql db.
From NLog docs:
NLog is designed to swallow run-time exceptions that may result from logging. The following settings can change this behavior and/or redirect these messages.
<nlog throwExceptions="true" /> - adding the throwExceptions attribute in the config file causes NLog to stop masking exceptions and pass them to the calling application instead. This attribute is useful at deployment time to quickly locate any problems. It’s recommended to set throwExceptions to "false" as soon as the application is properly configured to run, so that any accidental logging problems won’t crash the application.
<nlog internalLogFile="file.txt" /> - adding internalLogFile causes NLog to write its internal debugging messages to the specified file. This includes any exceptions that may be thrown during logging.
<nlog internalLogLevel="Trace|Debug|Info|Warn|Error|Fatal" /> – determines the internal log level. The higher the level, the less verbose the internal log output.
<nlog internalLogToConsole="false|true" /> – determines whether internal logging messages are sent to the console.
<nlog internalLogToConsoleError="false|true" /> – determines whether internal logging messages are sent to the console error output (stderr).
Right click on NLog configuration file. Set value to "Copy always" of property "Copy to Output Directory"